tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / ucb / source / ucp / file / filglob.cxx
blob7f10f8e5fe00a3363af09e8f0873a9fc045f5241
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include "filglob.hxx"
25 #include "filerror.hxx"
26 #include "bc.hxx"
27 #include <osl/file.hxx>
28 #include <ucbhelper/cancelcommandexecution.hxx>
29 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
30 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include <com/sun/star/ucb/IOErrorCode.hpp>
33 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
34 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
35 #include <com/sun/star/ucb/NameClashException.hpp>
36 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
37 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
38 #include <com/sun/star/beans/PropertyState.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
41 #include <com/sun/star/uno/Any.hxx>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <o3tl/string_view.hxx>
44 #include <o3tl/underlyingenumvalue.hxx>
45 #include <osl/diagnose.h>
46 #include <rtl/uri.hxx>
47 #include <rtl/ustring.hxx>
48 #include <sal/types.h>
50 using namespace ucbhelper;
51 using namespace osl;
52 using namespace ::com::sun::star;
53 using namespace com::sun::star::task;
54 using namespace com::sun::star::beans;
55 using namespace com::sun::star::lang;
56 using namespace com::sun::star::uno;
57 using namespace com::sun::star::ucb;
59 namespace {
61 Sequence< Any > generateErrorArguments(
62 OUString const & rPhysicalUrl)
64 OUString aResourceName;
65 OUString aResourceType;
66 bool bRemovable = false;
67 bool bResourceName = false;
68 bool bResourceType = false;
69 bool bRemoveProperty = false;
71 if (osl::FileBase::getSystemPathFromFileURL(
72 rPhysicalUrl,
73 aResourceName)
74 == osl::FileBase::E_None)
75 bResourceName = true;
77 // The resource types "folder" (i.e., directory) and
78 // "volume" seem to be
79 // the most interesting when producing meaningful error messages:
80 osl::DirectoryItem aItem;
81 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
82 osl::FileBase::E_None)
84 osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
85 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
86 switch (aStatus.getFileType())
88 case osl::FileStatus::Directory:
89 aResourceType = "folder";
90 bResourceType = true;
91 break;
93 case osl::FileStatus::Volume:
95 aResourceType = "volume";
96 bResourceType = true;
97 osl::VolumeInfo aVolumeInfo(
98 osl_VolumeInfo_Mask_Attributes );
99 if( osl::Directory::getVolumeInfo(
100 rPhysicalUrl,aVolumeInfo ) ==
101 osl::FileBase::E_None )
103 bRemovable = aVolumeInfo.getRemoveableFlag();
104 bRemoveProperty = true;
107 break;
108 case osl::FileStatus::Regular:
109 case osl::FileStatus::Fifo:
110 case osl::FileStatus::Socket:
111 case osl::FileStatus::Link:
112 case osl::FileStatus::Special:
113 case osl::FileStatus::Unknown:
114 // do nothing for now
115 break;
119 Sequence< Any > aArguments( 1 +
120 (bResourceName ? 1 : 0) +
121 (bResourceType ? 1 : 0) +
122 (bRemoveProperty ? 1 : 0) );
123 auto pArguments = aArguments.getArray();
124 sal_Int32 i = 0;
125 pArguments[i++]
126 <<= PropertyValue(u"Uri"_ustr,
128 Any(rPhysicalUrl),
129 PropertyState_DIRECT_VALUE);
130 if (bResourceName)
131 pArguments[i++]
132 <<= PropertyValue(u"ResourceName"_ustr,
134 Any(aResourceName),
135 PropertyState_DIRECT_VALUE);
136 if (bResourceType)
137 pArguments[i++]
138 <<= PropertyValue(u"ResourceType"_ustr,
140 Any(aResourceType),
141 PropertyState_DIRECT_VALUE);
142 if (bRemoveProperty)
143 pArguments[i++]
144 <<= PropertyValue(u"Removable"_ustr,
146 Any(bRemovable),
147 PropertyState_DIRECT_VALUE);
149 return aArguments;
154 namespace fileaccess {
157 bool isChild( std::u16string_view srcUnqPath,
158 std::u16string_view dstUnqPath )
160 static const sal_Unicode slash = '/';
161 // Simple lexical comparison
162 size_t srcL = srcUnqPath.size();
163 size_t dstL = dstUnqPath.size();
165 return (
166 ( srcUnqPath == dstUnqPath )
168 ( ( dstL > srcL )
170 o3tl::starts_with(dstUnqPath, srcUnqPath)
172 ( dstUnqPath[ srcL ] == slash ) )
177 OUString newName(
178 std::u16string_view aNewPrefix,
179 std::u16string_view aOldPrefix,
180 std::u16string_view old_Name )
182 size_t srcL = aOldPrefix.size();
184 return OUString::Concat(aNewPrefix) + old_Name.substr( srcL );
188 std::u16string_view getTitle( std::u16string_view aPath )
190 size_t lastIndex = aPath.rfind( '/' );
191 return aPath.substr((lastIndex != std::u16string_view::npos) ? lastIndex + 1 : 0);
195 OUString getParentName( std::u16string_view aFileName )
197 size_t lastIndex = aFileName.rfind( '/' );
198 OUString aParent( aFileName.substr( 0,lastIndex ) );
200 if( aParent.endsWith(":") && aParent.getLength() == 6 )
201 aParent += "/";
203 if ( aParent == "file://" )
204 aParent = "file:///";
206 return aParent;
210 osl::FileBase::RC osl_File_copy( const OUString& strPath,
211 const OUString& strDestPath,
212 bool test )
214 if( test )
216 osl::DirectoryItem aItem;
217 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
218 return osl::FileBase::E_EXIST;
221 return osl::File::copy( strPath,strDestPath );
225 osl::FileBase::RC osl_File_move( const OUString& strPath,
226 const OUString& strDestPath,
227 bool test )
229 if( test )
231 osl::DirectoryItem aItem;
232 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
233 return osl::FileBase::E_EXIST;
236 return osl::File::move( strPath,strDestPath );
239 void throw_handler(
240 TaskHandlerErr errorCode,
241 sal_Int32 minorCode,
242 const Reference< XCommandEnvironment >& xEnv,
243 const OUString& aUncPath,
244 BaseContent* pContent,
245 bool isHandled )
247 Reference<XCommandProcessor> xComProc(pContent);
248 Any aAny;
249 IOErrorCode ioErrorCode;
251 if( errorCode == TaskHandlerErr::UNSUPPORTED_COMMAND )
253 aAny <<= UnsupportedCommandException( OSL_LOG_PREFIX );
254 cancelCommandExecution( aAny,xEnv );
256 else if( errorCode == TaskHandlerErr::WRONG_SETPROPERTYVALUES_ARGUMENT ||
257 errorCode == TaskHandlerErr::WRONG_GETPROPERTYVALUES_ARGUMENT ||
258 errorCode == TaskHandlerErr::WRONG_OPEN_ARGUMENT ||
259 errorCode == TaskHandlerErr::WRONG_DELETE_ARGUMENT ||
260 errorCode == TaskHandlerErr::WRONG_TRANSFER_ARGUMENT ||
261 errorCode == TaskHandlerErr::WRONG_INSERT_ARGUMENT ||
262 errorCode == TaskHandlerErr::WRONG_CREATENEWCONTENT_ARGUMENT )
264 IllegalArgumentException excep;
265 excep.ArgumentPosition = 0;
266 cancelCommandExecution(Any(excep), xEnv);
268 else if( errorCode == TaskHandlerErr::UNSUPPORTED_OPEN_MODE )
270 UnsupportedOpenModeException excep;
271 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
272 cancelCommandExecution( Any(excep),xEnv );
274 else if(errorCode == TaskHandlerErr::DELETED_STATE_IN_OPEN_COMMAND ||
275 errorCode == TaskHandlerErr::INSERTED_STATE_IN_OPEN_COMMAND ||
276 errorCode == TaskHandlerErr::NOFRESHINSERT_IN_INSERT_COMMAND )
278 // What to do here?
280 else if(
281 // error in opening file
282 errorCode == TaskHandlerErr::NO_OPEN_FILE_FOR_OVERWRITE ||
283 // error in opening file
284 errorCode == TaskHandlerErr::NO_OPEN_FILE_FOR_WRITE ||
285 // error in opening file
286 errorCode == TaskHandlerErr::OPEN_FOR_STREAM ||
287 // error in opening file
288 errorCode == TaskHandlerErr::OPEN_FOR_INPUTSTREAM ||
289 // error in opening file
290 errorCode == TaskHandlerErr::OPEN_FILE_FOR_PAGING )
292 switch( minorCode )
294 case FileBase::E_NAMETOOLONG:
295 // pathname was too long
296 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
297 break;
298 case FileBase::E_NXIO:
299 // No such device or address
300 case FileBase::E_NODEV:
301 // No such device
302 ioErrorCode = IOErrorCode_INVALID_DEVICE;
303 break;
304 case FileBase::E_NOTDIR:
305 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
306 break;
307 case FileBase::E_NOENT:
308 // No such file or directory
309 ioErrorCode = IOErrorCode_NOT_EXISTING;
310 break;
311 case FileBase::E_ROFS:
312 // #i4735# handle ROFS transparently as ACCESS_DENIED
313 case FileBase::E_ACCES:
314 case FileBase::E_PERM:
315 // permission denied<P>
316 ioErrorCode = IOErrorCode_ACCESS_DENIED;
317 break;
318 case FileBase::E_ISDIR:
319 // Is a directory<p>
320 ioErrorCode = IOErrorCode_NO_FILE;
321 break;
322 case FileBase::E_NOTREADY:
323 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
324 break;
325 case FileBase::E_MFILE:
326 // too many open files used by the process
327 case FileBase::E_NFILE:
328 // too many open files in the system
329 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
330 break;
331 case FileBase::E_INVAL:
332 // the format of the parameters was not valid
333 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
334 break;
335 case FileBase::E_NOMEM:
336 // not enough memory for allocating structures
337 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
338 break;
339 case FileBase::E_BUSY: // Text file busy
340 case FileBase::E_AGAIN: // Operation would block
341 case FileBase::E_NOLCK: // No record locks available
342 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
343 break;
344 case FileBase::E_NOSYS:
345 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
346 break;
347 case FileBase::E_FAULT: // Bad address
348 case FileBase::E_LOOP: // Too many symbolic links encountered
349 case FileBase::E_NOSPC: // No space left on device
350 case FileBase::E_INTR: // function call was interrupted
351 case FileBase::E_IO: // I/O error
352 case FileBase::E_MULTIHOP: // Multihop attempted
353 case FileBase::E_NOLINK: // Link has been severed
354 default:
355 ioErrorCode = IOErrorCode_GENERAL;
356 break;
359 cancelCommandExecution(
360 ioErrorCode,
361 generateErrorArguments(aUncPath),
362 xEnv,
363 "an error occurred during file opening ("
364 + OUString::number(o3tl::to_underlying(errorCode)) + "/"
365 + OUString::number(minorCode) + ")",
366 xComProc);
368 else if( errorCode == TaskHandlerErr::OPEN_FOR_DIRECTORYLISTING ||
369 errorCode == TaskHandlerErr::OPENDIRECTORY_FOR_REMOVE )
371 switch( minorCode )
373 case FileBase::E_INVAL:
374 // the format of the parameters was not valid
375 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
376 break;
377 case FileBase::E_NOENT:
378 // the specified path doesn't exist
379 ioErrorCode = IOErrorCode_NOT_EXISTING;
380 break;
381 case FileBase::E_NOTDIR:
382 // the specified path is not a directory
383 ioErrorCode = IOErrorCode_NO_DIRECTORY;
384 break;
385 case FileBase::E_NOMEM:
386 // not enough memory for allocating structures
387 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
388 break;
389 case FileBase::E_ROFS:
390 // #i4735# handle ROFS transparently as ACCESS_DENIED
391 case FileBase::E_ACCES: // permission denied
392 ioErrorCode = IOErrorCode_ACCESS_DENIED;
393 break;
394 case FileBase::E_NOTREADY:
395 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
396 break;
397 case FileBase::E_MFILE:
398 // too many open files used by the process
399 case FileBase::E_NFILE:
400 // too many open files in the system
401 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
402 break;
403 case FileBase::E_NAMETOOLONG:
404 // File name too long
405 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
406 break;
407 case FileBase::E_LOOP:
408 // Too many symbolic links encountered<p>
409 default:
410 ioErrorCode = IOErrorCode_GENERAL;
411 break;
414 cancelCommandExecution(
415 ioErrorCode,
416 generateErrorArguments(aUncPath),
417 xEnv,
418 u"an error occurred during opening a directory"_ustr,
419 xComProc);
421 else if( errorCode == TaskHandlerErr::NOTCONNECTED_FOR_WRITE ||
422 errorCode == TaskHandlerErr::BUFFERSIZEEXCEEDED_FOR_WRITE ||
423 errorCode == TaskHandlerErr::IOEXCEPTION_FOR_WRITE ||
424 errorCode == TaskHandlerErr::NOTCONNECTED_FOR_PAGING ||
425 errorCode == TaskHandlerErr::BUFFERSIZEEXCEEDED_FOR_PAGING ||
426 errorCode == TaskHandlerErr::IOEXCEPTION_FOR_PAGING )
428 ioErrorCode = IOErrorCode_UNKNOWN;
429 cancelCommandExecution(
430 ioErrorCode,
431 generateErrorArguments(aUncPath),
432 xEnv,
433 u"an error occurred writing or reading from a file"_ustr,
434 xComProc );
436 else if( errorCode == TaskHandlerErr::FILEIOERROR_FOR_NO_SPACE )
438 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
439 cancelCommandExecution(
440 ioErrorCode,
441 generateErrorArguments(aUncPath),
442 xEnv,
443 u"device full"_ustr,
444 xComProc);
446 else if( errorCode == TaskHandlerErr::FILEIOERROR_FOR_WRITE ||
447 errorCode == TaskHandlerErr::READING_FILE_FOR_PAGING )
449 switch( minorCode )
451 case FileBase::E_INVAL:
452 // the format of the parameters was not valid
453 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
454 break;
455 case FileBase::E_FBIG:
456 // File too large
457 ioErrorCode = IOErrorCode_CANT_WRITE;
458 break;
459 case FileBase::E_NOSPC:
460 // No space left on device
461 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
462 break;
463 case FileBase::E_NXIO:
464 // No such device or address
465 ioErrorCode = IOErrorCode_INVALID_DEVICE;
466 break;
467 case FileBase::E_NOLINK:
468 // Link has been severed
469 case FileBase::E_ISDIR:
470 // Is a directory
471 ioErrorCode = IOErrorCode_NO_FILE;
472 break;
473 case FileBase::E_AGAIN: // Operation would block
474 case FileBase::E_NOLCK: // No record locks available
475 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
476 break;
477 case FileBase::E_TIMEDOUT:
478 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
479 break;
480 case FileBase::E_IO: // I/O error
481 case FileBase::E_BADF: // Bad file
482 case FileBase::E_FAULT: // Bad address
483 case FileBase::E_INTR: // function call was interrupted
484 default:
485 ioErrorCode = IOErrorCode_GENERAL;
486 break;
488 cancelCommandExecution(
489 ioErrorCode,
490 generateErrorArguments(aUncPath),
491 xEnv,
492 u"an error occurred during opening a file"_ustr,
493 xComProc);
495 else if( errorCode == TaskHandlerErr::NONAMESET_INSERT_COMMAND ||
496 errorCode == TaskHandlerErr::NOCONTENTTYPE_INSERT_COMMAND )
498 static constexpr OUString sTitle = u"Title"_ustr;
499 static constexpr OUString sContentType = u"ContentType"_ustr;
500 Sequence< OUString > aSeq{ (errorCode == TaskHandlerErr::NONAMESET_INSERT_COMMAND)
501 ? sTitle
502 : sContentType };
504 aAny <<= MissingPropertiesException(
505 u"a property is missing, necessary to create a content"_ustr,
506 xComProc,
507 aSeq);
508 cancelCommandExecution(aAny,xEnv);
510 else if( errorCode == TaskHandlerErr::FILESIZE_FOR_WRITE )
512 switch( minorCode )
514 case FileBase::E_INVAL:
515 // the format of the parameters was not valid
516 case FileBase::E_OVERFLOW:
517 // The resulting file offset would be a value which cannot
518 // be represented correctly for regular files
519 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
520 break;
521 default:
522 ioErrorCode = IOErrorCode_GENERAL;
523 break;
525 cancelCommandExecution(
526 ioErrorCode,
527 generateErrorArguments(aUncPath),
528 xEnv,
529 u"there were problems with the filesize"_ustr,
530 xComProc);
532 else if(errorCode == TaskHandlerErr::INPUTSTREAM_FOR_WRITE)
534 aAny <<=
535 MissingInputStreamException(
536 u"the inputstream is missing, necessary to create a content"_ustr,
537 xComProc);
538 cancelCommandExecution(aAny,xEnv);
540 else if( errorCode == TaskHandlerErr::NOREPLACE_FOR_WRITE )
541 // Overwrite = false and file exists
543 NameClashException excep(u"file exists and overwrite forbidden"_ustr,
544 Reference<XInterface>(xComProc, UNO_QUERY),
545 InteractionClassification_ERROR, OUString(getTitle(aUncPath)));
546 cancelCommandExecution( Any(excep), xEnv );
548 else if( errorCode == TaskHandlerErr::INVALID_NAME_MKDIR )
550 PropertyValue prop;
551 prop.Name = "ResourceName";
552 prop.Handle = -1;
553 OUString aClashingName(
554 rtl::Uri::decode(
555 OUString(getTitle(aUncPath)),
556 rtl_UriDecodeWithCharset,
557 RTL_TEXTENCODING_UTF8));
558 prop.Value <<= aClashingName;
559 InteractiveAugmentedIOException excep(
560 u"the name contained invalid characters"_ustr, Reference<XInterface>(xComProc, UNO_QUERY),
561 InteractionClassification_ERROR, IOErrorCode_INVALID_CHARACTER, { Any(prop) });
562 if(isHandled)
563 throw excep;
564 cancelCommandExecution( Any(excep), xEnv );
565 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
566 // cancelCommandExecution(
567 // ioErrorCode,
568 // generateErrorArguments(aUncPath),
569 // xEnv,
570 // OUString( "the name contained invalid characters"),
571 // xComProc );
573 else if( errorCode == TaskHandlerErr::FOLDER_EXISTS_MKDIR )
575 NameClashException excep(u"folder exists and overwrite forbidden"_ustr, xComProc,
576 InteractionClassification_ERROR, OUString(getTitle(aUncPath)));
577 if(isHandled)
578 throw excep;
579 cancelCommandExecution( Any(excep), xEnv );
580 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
581 // cancelCommandExecution(
582 // ioErrorCode,
583 // generateErrorArguments(aUncPath),
584 // xEnv,
585 // OUString( "the folder exists"),
586 // xComProc );
588 else if( errorCode == TaskHandlerErr::ENSUREDIR_FOR_WRITE ||
589 errorCode == TaskHandlerErr::CREATEDIRECTORY_MKDIR )
591 switch( minorCode )
593 case FileBase::E_ACCES:
594 ioErrorCode = IOErrorCode_ACCESS_DENIED;
595 break;
596 case FileBase::E_ROFS:
597 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
598 break;
599 case FileBase::E_NAMETOOLONG:
600 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
601 break;
602 default:
603 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
604 break;
606 cancelCommandExecution(
607 ioErrorCode,
608 generateErrorArguments(getParentName(aUncPath)),
609 //TODO! ok to supply physical URL to getParentName()?
610 xEnv,
611 u"a folder could not be created"_ustr,
612 xComProc );
614 else if( errorCode == TaskHandlerErr::VALIDFILESTATUSWHILE_FOR_REMOVE ||
615 errorCode == TaskHandlerErr::VALIDFILESTATUS_FOR_REMOVE ||
616 errorCode == TaskHandlerErr::NOSUCHFILEORDIR_FOR_REMOVE )
618 switch( minorCode )
620 case FileBase::E_INVAL: // the format of the parameters was not valid
621 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
622 break;
623 case FileBase::E_NOMEM: // not enough memory for allocating structures
624 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
625 break;
626 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
627 case FileBase::E_ACCES: // permission denied
628 ioErrorCode = IOErrorCode_ACCESS_DENIED;
629 break;
630 case FileBase::E_MFILE: // too many open files used by the process
631 case FileBase::E_NFILE: // too many open files in the system
632 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
633 break;
634 case FileBase::E_NOLINK: // Link has been severed
635 case FileBase::E_NOENT: // No such file or directory
636 ioErrorCode = IOErrorCode_NOT_EXISTING;
637 break;
638 case FileBase::E_NAMETOOLONG: // File name too long
639 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
640 break;
641 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
642 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
643 break;
644 case FileBase::E_LOOP: // Too many symbolic links encountered
645 case FileBase::E_IO: // I/O error
646 case FileBase::E_MULTIHOP: // Multihop attempted
647 case FileBase::E_FAULT: // Bad address
648 case FileBase::E_INTR: // function call was interrupted
649 case FileBase::E_NOSYS: // Function not implemented
650 case FileBase::E_NOSPC: // No space left on device
651 case FileBase::E_NXIO: // No such device or address
652 case FileBase::E_OVERFLOW: // Value too large for defined data type
653 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
654 default:
655 ioErrorCode = IOErrorCode_GENERAL;
656 break;
658 cancelCommandExecution(
659 ioErrorCode,
660 generateErrorArguments(aUncPath),
661 xEnv,
662 u"a file status object could not be filled"_ustr,
663 xComProc );
665 else if( errorCode == TaskHandlerErr::DELETEFILE_FOR_REMOVE ||
666 errorCode == TaskHandlerErr::DELETEDIRECTORY_FOR_REMOVE )
668 switch( minorCode )
670 case FileBase::E_INVAL: // the format of the parameters was not valid
671 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
672 break;
673 case FileBase::E_NOMEM: // not enough memory for allocating structures
674 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
675 break;
676 case FileBase::E_ACCES: // Permission denied
677 ioErrorCode = IOErrorCode_ACCESS_DENIED;
678 break;
679 case FileBase::E_PERM: // Operation not permitted
680 case FileBase::E_ISDIR: // Is a directory
681 case FileBase::E_ROFS: // Read-only file system
682 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
683 break;
684 case FileBase::E_NAMETOOLONG: // File name too long
685 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
686 break;
687 case FileBase::E_NOLINK: // Link has been severed
688 case FileBase::E_NOENT: // No such file or directory
689 ioErrorCode = IOErrorCode_NOT_EXISTING;
690 break;
691 case FileBase::E_BUSY: // Device or resource busy
692 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
693 break;
694 case FileBase::E_FAULT: // Bad address
695 case FileBase::E_LOOP: // Too many symbolic links encountered
696 case FileBase::E_IO: // I/O error
697 case FileBase::E_INTR: // function call was interrupted
698 case FileBase::E_MULTIHOP: // Multihop attempted
699 default:
700 ioErrorCode = IOErrorCode_GENERAL;
701 break;
703 cancelCommandExecution(
704 ioErrorCode,
705 generateErrorArguments(aUncPath),
706 xEnv,
707 u"a file or directory could not be deleted"_ustr,
708 xComProc );
710 else if( errorCode == TaskHandlerErr::TRANSFER_BY_COPY_SOURCE ||
711 errorCode == TaskHandlerErr::TRANSFER_BY_COPY_SOURCESTAT ||
712 errorCode == TaskHandlerErr::TRANSFER_BY_MOVE_SOURCE ||
713 errorCode == TaskHandlerErr::TRANSFER_BY_MOVE_SOURCESTAT ||
714 errorCode == TaskHandlerErr::TRANSFER_DESTFILETYPE ||
715 errorCode == TaskHandlerErr::FILETYPE_FOR_REMOVE ||
716 errorCode == TaskHandlerErr::DIRECTORYEXHAUSTED_FOR_REMOVE ||
717 errorCode == TaskHandlerErr::TRANSFER_INVALIDURL )
719 OUString aMsg;
720 switch( minorCode )
722 case FileBase::E_NOENT: // No such file or directory
723 if ( errorCode == TaskHandlerErr::TRANSFER_BY_COPY_SOURCE ||
724 errorCode == TaskHandlerErr::TRANSFER_BY_COPY_SOURCESTAT ||
725 errorCode == TaskHandlerErr::TRANSFER_BY_MOVE_SOURCE ||
726 errorCode == TaskHandlerErr::TRANSFER_BY_MOVE_SOURCESTAT )
728 ioErrorCode = IOErrorCode_NOT_EXISTING;
729 aMsg = "source file/folder does not exist";
730 break;
732 else
734 ioErrorCode = IOErrorCode_GENERAL;
735 aMsg = "a general error during transfer command";
736 break;
738 default:
739 ioErrorCode = IOErrorCode_GENERAL;
740 aMsg = "a general error during transfer command";
741 break;
743 cancelCommandExecution(
744 ioErrorCode,
745 generateErrorArguments(aUncPath),
746 xEnv,
747 aMsg,
748 xComProc );
750 else if( errorCode == TaskHandlerErr::TRANSFER_INVALIDSCHEME )
752 aAny <<= InteractiveBadTransferURLException(
753 u"bad transfer url"_ustr,
754 xComProc);
755 cancelCommandExecution( aAny,xEnv );
757 else if( errorCode == TaskHandlerErr::OVERWRITE_FOR_MOVE ||
758 errorCode == TaskHandlerErr::OVERWRITE_FOR_COPY ||
759 errorCode == TaskHandlerErr::NAMECLASHMOVE_FOR_MOVE ||
760 errorCode == TaskHandlerErr::NAMECLASHMOVE_FOR_COPY ||
761 errorCode == TaskHandlerErr::KEEPERROR_FOR_MOVE ||
762 errorCode == TaskHandlerErr::KEEPERROR_FOR_COPY ||
763 errorCode == TaskHandlerErr::RENAME_FOR_MOVE ||
764 errorCode == TaskHandlerErr::RENAME_FOR_COPY ||
765 errorCode == TaskHandlerErr::RENAMEMOVE_FOR_MOVE ||
766 errorCode == TaskHandlerErr::RENAMEMOVE_FOR_COPY )
768 OUString aMsg(
769 u"general error during transfer"_ustr);
771 switch( minorCode )
773 case FileBase::E_EXIST:
774 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
775 break;
776 case FileBase::E_INVAL: // the format of the parameters was not valid
777 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
778 break;
779 case FileBase::E_NOMEM: // not enough memory for allocating structures
780 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
781 break;
782 case FileBase::E_ACCES: // Permission denied
783 ioErrorCode = IOErrorCode_ACCESS_DENIED;
784 break;
785 case FileBase::E_PERM: // Operation not permitted
786 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
787 break;
788 case FileBase::E_NAMETOOLONG: // File name too long
789 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
790 break;
791 case FileBase::E_NOENT: // No such file or directory
792 ioErrorCode = IOErrorCode_NOT_EXISTING;
793 aMsg = "file/folder does not exist";
794 break;
795 case FileBase::E_ROFS: // Read-only file system<p>
796 ioErrorCode = IOErrorCode_NOT_EXISTING;
797 break;
798 default:
799 ioErrorCode = IOErrorCode_GENERAL;
800 break;
802 cancelCommandExecution(
803 ioErrorCode,
804 generateErrorArguments(aUncPath),
805 xEnv,
806 aMsg,
807 xComProc );
809 else if( errorCode == TaskHandlerErr::NAMECLASH_FOR_COPY ||
810 errorCode == TaskHandlerErr::NAMECLASH_FOR_MOVE )
812 NameClashException excep(u"name clash during copy or move"_ustr,
813 Reference<XInterface>(xComProc, UNO_QUERY),
814 InteractionClassification_ERROR, OUString(getTitle(aUncPath)));
816 cancelCommandExecution(Any(excep), xEnv);
818 else if( errorCode == TaskHandlerErr::NAMECLASHSUPPORT_FOR_MOVE ||
819 errorCode == TaskHandlerErr::NAMECLASHSUPPORT_FOR_COPY )
821 UnsupportedNameClashException excep(
822 u"name clash value not supported during copy or move"_ustr,
823 Reference<XInterface>(xComProc, UNO_QUERY), minorCode);
825 cancelCommandExecution(Any(excep), xEnv);
827 else
829 // case TaskHandlerErr::NO_ERROR:
830 return;
835 } // end namespace fileaccess
837 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */