Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / file / filglob.cxx
bloba86716509a2482dfbd4ddf1545c6fa4a8b1b0aab
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 <osl/diagnose.h>
45 #include <rtl/uri.hxx>
46 #include <rtl/ustring.hxx>
47 #include <sal/types.h>
49 using namespace ucbhelper;
50 using namespace osl;
51 using namespace ::com::sun::star;
52 using namespace com::sun::star::task;
53 using namespace com::sun::star::beans;
54 using namespace com::sun::star::lang;
55 using namespace com::sun::star::uno;
56 using namespace com::sun::star::ucb;
58 namespace {
60 Sequence< Any > generateErrorArguments(
61 OUString const & rPhysicalUrl)
63 OUString aResourceName;
64 OUString aResourceType;
65 bool bRemovable = false;
66 bool bResourceName = false;
67 bool bResourceType = false;
68 bool bRemoveProperty = false;
70 if (osl::FileBase::getSystemPathFromFileURL(
71 rPhysicalUrl,
72 aResourceName)
73 == osl::FileBase::E_None)
74 bResourceName = true;
76 // The resource types "folder" (i.e., directory) and
77 // "volume" seem to be
78 // the most interesting when producing meaningful error messages:
79 osl::DirectoryItem aItem;
80 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
81 osl::FileBase::E_None)
83 osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
84 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
85 switch (aStatus.getFileType())
87 case osl::FileStatus::Directory:
88 aResourceType = "folder";
89 bResourceType = true;
90 break;
92 case osl::FileStatus::Volume:
94 aResourceType = "volume";
95 bResourceType = true;
96 osl::VolumeInfo aVolumeInfo(
97 osl_VolumeInfo_Mask_Attributes );
98 if( osl::Directory::getVolumeInfo(
99 rPhysicalUrl,aVolumeInfo ) ==
100 osl::FileBase::E_None )
102 bRemovable = aVolumeInfo.getRemoveableFlag();
103 bRemoveProperty = true;
106 break;
107 case osl::FileStatus::Regular:
108 case osl::FileStatus::Fifo:
109 case osl::FileStatus::Socket:
110 case osl::FileStatus::Link:
111 case osl::FileStatus::Special:
112 case osl::FileStatus::Unknown:
113 // do nothing for now
114 break;
118 Sequence< Any > aArguments( 1 +
119 (bResourceName ? 1 : 0) +
120 (bResourceType ? 1 : 0) +
121 (bRemoveProperty ? 1 : 0) );
122 auto pArguments = aArguments.getArray();
123 sal_Int32 i = 0;
124 pArguments[i++]
125 <<= PropertyValue("Uri",
127 Any(rPhysicalUrl),
128 PropertyState_DIRECT_VALUE);
129 if (bResourceName)
130 pArguments[i++]
131 <<= PropertyValue("ResourceName",
133 Any(aResourceName),
134 PropertyState_DIRECT_VALUE);
135 if (bResourceType)
136 pArguments[i++]
137 <<= PropertyValue("ResourceType",
139 Any(aResourceType),
140 PropertyState_DIRECT_VALUE);
141 if (bRemoveProperty)
142 pArguments[i++]
143 <<= PropertyValue("Removable",
145 Any(bRemovable),
146 PropertyState_DIRECT_VALUE);
148 return aArguments;
153 namespace fileaccess {
156 bool isChild( std::u16string_view srcUnqPath,
157 std::u16string_view dstUnqPath )
159 static const sal_Unicode slash = '/';
160 // Simple lexical comparison
161 size_t srcL = srcUnqPath.size();
162 size_t dstL = dstUnqPath.size();
164 return (
165 ( srcUnqPath == dstUnqPath )
167 ( ( dstL > srcL )
169 o3tl::starts_with(dstUnqPath, srcUnqPath)
171 ( dstUnqPath[ srcL ] == slash ) )
176 OUString newName(
177 std::u16string_view aNewPrefix,
178 std::u16string_view aOldPrefix,
179 std::u16string_view old_Name )
181 size_t srcL = aOldPrefix.size();
183 return OUString::Concat(aNewPrefix) + old_Name.substr( srcL );
187 std::u16string_view getTitle( std::u16string_view aPath )
189 size_t lastIndex = aPath.rfind( '/' );
190 return aPath.substr( lastIndex + 1 );
194 OUString getParentName( std::u16string_view aFileName )
196 size_t lastIndex = aFileName.rfind( '/' );
197 OUString aParent( aFileName.substr( 0,lastIndex ) );
199 if( aParent.endsWith(":") && aParent.getLength() == 6 )
200 aParent += "/";
202 if ( aParent == "file://" )
203 aParent = "file:///";
205 return aParent;
209 osl::FileBase::RC osl_File_copy( const OUString& strPath,
210 const OUString& strDestPath,
211 bool test )
213 if( test )
215 osl::DirectoryItem aItem;
216 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
217 return osl::FileBase::E_EXIST;
220 return osl::File::copy( strPath,strDestPath );
224 osl::FileBase::RC osl_File_move( const OUString& strPath,
225 const OUString& strDestPath,
226 bool test )
228 if( test )
230 osl::DirectoryItem aItem;
231 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
232 return osl::FileBase::E_EXIST;
235 return osl::File::move( strPath,strDestPath );
238 void throw_handler(
239 sal_Int32 errorCode,
240 sal_Int32 minorCode,
241 const Reference< XCommandEnvironment >& xEnv,
242 const OUString& aUncPath,
243 BaseContent* pContent,
244 bool isHandled )
246 Reference<XCommandProcessor> xComProc(pContent);
247 Any aAny;
248 IOErrorCode ioErrorCode;
250 if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
252 aAny <<= UnsupportedCommandException( OSL_LOG_PREFIX );
253 cancelCommandExecution( aAny,xEnv );
255 else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
256 errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
257 errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
258 errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
259 errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
260 errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT ||
261 errorCode == TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT )
263 IllegalArgumentException excep;
264 excep.ArgumentPosition = 0;
265 cancelCommandExecution(Any(excep), xEnv);
267 else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
269 UnsupportedOpenModeException excep;
270 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
271 cancelCommandExecution( Any(excep),xEnv );
273 else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
274 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
275 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
277 // What to do here?
279 else if(
280 // error in opening file
281 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
282 // error in opening file
283 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
284 // error in opening file
285 errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
286 // error in opening file
287 errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
288 // error in opening file
289 errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
291 switch( minorCode )
293 case FileBase::E_NAMETOOLONG:
294 // pathname was too long
295 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
296 break;
297 case FileBase::E_NXIO:
298 // No such device or address
299 case FileBase::E_NODEV:
300 // No such device
301 ioErrorCode = IOErrorCode_INVALID_DEVICE;
302 break;
303 case FileBase::E_NOTDIR:
304 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
305 break;
306 case FileBase::E_NOENT:
307 // No such file or directory
308 ioErrorCode = IOErrorCode_NOT_EXISTING;
309 break;
310 case FileBase::E_ROFS:
311 // #i4735# handle ROFS transparently as ACCESS_DENIED
312 case FileBase::E_ACCES:
313 case FileBase::E_PERM:
314 // permission denied<P>
315 ioErrorCode = IOErrorCode_ACCESS_DENIED;
316 break;
317 case FileBase::E_ISDIR:
318 // Is a directory<p>
319 ioErrorCode = IOErrorCode_NO_FILE;
320 break;
321 case FileBase::E_NOTREADY:
322 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
323 break;
324 case FileBase::E_MFILE:
325 // too many open files used by the process
326 case FileBase::E_NFILE:
327 // too many open files in the system
328 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
329 break;
330 case FileBase::E_INVAL:
331 // the format of the parameters was not valid
332 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
333 break;
334 case FileBase::E_NOMEM:
335 // not enough memory for allocating structures
336 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
337 break;
338 case FileBase::E_BUSY:
339 // Text file busy
340 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
341 break;
342 case FileBase::E_AGAIN:
343 // Operation would block
344 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
345 break;
346 case FileBase::E_NOLCK: // No record locks available
347 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
348 break;
349 case FileBase::E_NOSYS:
350 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
351 break;
352 case FileBase::E_FAULT: // Bad address
353 case FileBase::E_LOOP: // Too many symbolic links encountered
354 case FileBase::E_NOSPC: // No space left on device
355 case FileBase::E_INTR: // function call was interrupted
356 case FileBase::E_IO: // I/O error
357 case FileBase::E_MULTIHOP: // Multihop attempted
358 case FileBase::E_NOLINK: // Link has been severed
359 default:
360 ioErrorCode = IOErrorCode_GENERAL;
361 break;
364 cancelCommandExecution(
365 ioErrorCode,
366 generateErrorArguments(aUncPath),
367 xEnv,
368 "an error occurred during file opening",
369 xComProc);
371 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
372 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
374 switch( minorCode )
376 case FileBase::E_INVAL:
377 // the format of the parameters was not valid
378 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
379 break;
380 case FileBase::E_NOENT:
381 // the specified path doesn't exist
382 ioErrorCode = IOErrorCode_NOT_EXISTING;
383 break;
384 case FileBase::E_NOTDIR:
385 // the specified path is not a directory
386 ioErrorCode = IOErrorCode_NO_DIRECTORY;
387 break;
388 case FileBase::E_NOMEM:
389 // not enough memory for allocating structures
390 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
391 break;
392 case FileBase::E_ROFS:
393 // #i4735# handle ROFS transparently as ACCESS_DENIED
394 case FileBase::E_ACCES: // permission denied
395 ioErrorCode = IOErrorCode_ACCESS_DENIED;
396 break;
397 case FileBase::E_NOTREADY:
398 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
399 break;
400 case FileBase::E_MFILE:
401 // too many open files used by the process
402 case FileBase::E_NFILE:
403 // too many open files in the system
404 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
405 break;
406 case FileBase::E_NAMETOOLONG:
407 // File name too long
408 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
409 break;
410 case FileBase::E_LOOP:
411 // Too many symbolic links encountered<p>
412 default:
413 ioErrorCode = IOErrorCode_GENERAL;
414 break;
417 cancelCommandExecution(
418 ioErrorCode,
419 generateErrorArguments(aUncPath),
420 xEnv,
421 "an error occurred during opening a directory",
422 xComProc);
424 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
425 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
426 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
427 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
428 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
429 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
431 ioErrorCode = IOErrorCode_UNKNOWN;
432 cancelCommandExecution(
433 ioErrorCode,
434 generateErrorArguments(aUncPath),
435 xEnv,
436 "an error occurred writing or reading from a file",
437 xComProc );
439 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
441 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
442 cancelCommandExecution(
443 ioErrorCode,
444 generateErrorArguments(aUncPath),
445 xEnv,
446 "device full",
447 xComProc);
449 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
450 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
452 switch( minorCode )
454 case FileBase::E_INVAL:
455 // the format of the parameters was not valid
456 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
457 break;
458 case FileBase::E_FBIG:
459 // File too large
460 ioErrorCode = IOErrorCode_CANT_WRITE;
461 break;
462 case FileBase::E_NOSPC:
463 // No space left on device
464 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
465 break;
466 case FileBase::E_NXIO:
467 // No such device or address
468 ioErrorCode = IOErrorCode_INVALID_DEVICE;
469 break;
470 case FileBase::E_NOLINK:
471 // Link has been severed
472 case FileBase::E_ISDIR:
473 // Is a directory
474 ioErrorCode = IOErrorCode_NO_FILE;
475 break;
476 case FileBase::E_AGAIN:
477 // Operation would block
478 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
479 break;
480 case FileBase::E_TIMEDOUT:
481 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
482 break;
483 case FileBase::E_NOLCK: // No record locks available
484 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
485 break;
486 case FileBase::E_IO: // I/O error
487 case FileBase::E_BADF: // Bad file
488 case FileBase::E_FAULT: // Bad address
489 case FileBase::E_INTR: // function call was interrupted
490 default:
491 ioErrorCode = IOErrorCode_GENERAL;
492 break;
494 cancelCommandExecution(
495 ioErrorCode,
496 generateErrorArguments(aUncPath),
497 xEnv,
498 "an error occurred during opening a file",
499 xComProc);
501 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
502 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
504 static constexpr OUStringLiteral sTitle = u"Title";
505 static constexpr OUStringLiteral sContentType = u"ContentType";
506 Sequence< OUString > aSeq{ (errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND)
507 ? OUString(sTitle)
508 : OUString(sContentType) };
510 aAny <<= MissingPropertiesException(
511 "a property is missing, necessary to create a content",
512 xComProc,
513 aSeq);
514 cancelCommandExecution(aAny,xEnv);
516 else if( errorCode == TASKHANDLING_FILESIZE_FOR_WRITE )
518 switch( minorCode )
520 case FileBase::E_INVAL:
521 // the format of the parameters was not valid
522 case FileBase::E_OVERFLOW:
523 // The resulting file offset would be a value which cannot
524 // be represented correctly for regular files
525 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
526 break;
527 default:
528 ioErrorCode = IOErrorCode_GENERAL;
529 break;
531 cancelCommandExecution(
532 ioErrorCode,
533 generateErrorArguments(aUncPath),
534 xEnv,
535 "there were problems with the filesize",
536 xComProc);
538 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
540 aAny <<=
541 MissingInputStreamException(
542 "the inputstream is missing, necessary to create a content",
543 xComProc);
544 cancelCommandExecution(aAny,xEnv);
546 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
547 // Overwrite = false and file exists
549 NameClashException excep;
550 excep.Name = getTitle(aUncPath);
551 excep.Classification = InteractionClassification_ERROR;
552 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
553 excep.Message = "file exists and overwrite forbidden";
554 cancelCommandExecution( Any(excep), xEnv );
556 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
558 InteractiveAugmentedIOException excep;
559 excep.Code = IOErrorCode_INVALID_CHARACTER;
560 PropertyValue prop;
561 prop.Name = "ResourceName";
562 prop.Handle = -1;
563 OUString aClashingName(
564 rtl::Uri::decode(
565 OUString(getTitle(aUncPath)),
566 rtl_UriDecodeWithCharset,
567 RTL_TEXTENCODING_UTF8));
568 prop.Value <<= aClashingName;
569 excep.Arguments = { Any(prop) };
570 excep.Classification = InteractionClassification_ERROR;
571 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
572 excep.Message = "the name contained invalid characters";
573 if(isHandled)
574 throw excep;
575 cancelCommandExecution( Any(excep), xEnv );
576 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
577 // cancelCommandExecution(
578 // ioErrorCode,
579 // generateErrorArguments(aUncPath),
580 // xEnv,
581 // OUString( "the name contained invalid characters"),
582 // xComProc );
584 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
586 NameClashException excep;
587 excep.Name = getTitle(aUncPath);
588 excep.Classification = InteractionClassification_ERROR;
589 excep.Context = xComProc;
590 excep.Message = "folder exists and overwrite forbidden";
591 if(isHandled)
592 throw excep;
593 cancelCommandExecution( Any(excep), xEnv );
594 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
595 // cancelCommandExecution(
596 // ioErrorCode,
597 // generateErrorArguments(aUncPath),
598 // xEnv,
599 // OUString( "the folder exists"),
600 // xComProc );
602 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
603 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
605 switch( minorCode )
607 case FileBase::E_ACCES:
608 ioErrorCode = IOErrorCode_ACCESS_DENIED;
609 break;
610 case FileBase::E_ROFS:
611 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
612 break;
613 case FileBase::E_NAMETOOLONG:
614 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
615 break;
616 default:
617 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
618 break;
620 cancelCommandExecution(
621 ioErrorCode,
622 generateErrorArguments(getParentName(aUncPath)),
623 //TODO! ok to supply physical URL to getParentName()?
624 xEnv,
625 "a folder could not be created",
626 xComProc );
628 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
629 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
630 errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
632 switch( minorCode )
634 case FileBase::E_INVAL: // the format of the parameters was not valid
635 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
636 break;
637 case FileBase::E_NOMEM: // not enough memory for allocating structures
638 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
639 break;
640 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
641 case FileBase::E_ACCES: // permission denied
642 ioErrorCode = IOErrorCode_ACCESS_DENIED;
643 break;
644 case FileBase::E_MFILE: // too many open files used by the process
645 case FileBase::E_NFILE: // too many open files in the system
646 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
647 break;
648 case FileBase::E_NOLINK: // Link has been severed
649 case FileBase::E_NOENT: // No such file or directory
650 ioErrorCode = IOErrorCode_NOT_EXISTING;
651 break;
652 case FileBase::E_NAMETOOLONG: // File name too long
653 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
654 break;
655 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
656 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
657 break;
658 case FileBase::E_LOOP: // Too many symbolic links encountered
659 case FileBase::E_IO: // I/O error
660 case FileBase::E_MULTIHOP: // Multihop attempted
661 case FileBase::E_FAULT: // Bad address
662 case FileBase::E_INTR: // function call was interrupted
663 case FileBase::E_NOSYS: // Function not implemented
664 case FileBase::E_NOSPC: // No space left on device
665 case FileBase::E_NXIO: // No such device or address
666 case FileBase::E_OVERFLOW: // Value too large for defined data type
667 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
668 default:
669 ioErrorCode = IOErrorCode_GENERAL;
670 break;
672 cancelCommandExecution(
673 ioErrorCode,
674 generateErrorArguments(aUncPath),
675 xEnv,
676 "a file status object could not be filled",
677 xComProc );
679 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
680 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
682 switch( minorCode )
684 case FileBase::E_INVAL: // the format of the parameters was not valid
685 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
686 break;
687 case FileBase::E_NOMEM: // not enough memory for allocating structures
688 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
689 break;
690 case FileBase::E_ACCES: // Permission denied
691 ioErrorCode = IOErrorCode_ACCESS_DENIED;
692 break;
693 case FileBase::E_PERM: // Operation not permitted
694 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
695 break;
696 case FileBase::E_NAMETOOLONG: // File name too long
697 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
698 break;
699 case FileBase::E_NOLINK: // Link has been severed
700 case FileBase::E_NOENT: // No such file or directory
701 ioErrorCode = IOErrorCode_NOT_EXISTING;
702 break;
703 case FileBase::E_ISDIR: // Is a directory
704 case FileBase::E_ROFS: // Read-only file system
705 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
706 break;
707 case FileBase::E_BUSY: // Device or resource busy
708 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
709 break;
710 case FileBase::E_FAULT: // Bad address
711 case FileBase::E_LOOP: // Too many symbolic links encountered
712 case FileBase::E_IO: // I/O error
713 case FileBase::E_INTR: // function call was interrupted
714 case FileBase::E_MULTIHOP: // Multihop attempted
715 default:
716 ioErrorCode = IOErrorCode_GENERAL;
717 break;
719 cancelCommandExecution(
720 ioErrorCode,
721 generateErrorArguments(aUncPath),
722 xEnv,
723 "a file or directory could not be deleted",
724 xComProc );
726 else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
727 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
728 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
729 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
730 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
731 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
732 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
733 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
735 OUString aMsg;
736 switch( minorCode )
738 case FileBase::E_NOENT: // No such file or directory
739 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
740 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
741 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
742 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
744 ioErrorCode = IOErrorCode_NOT_EXISTING;
745 aMsg = "source file/folder does not exist";
746 break;
748 else
750 ioErrorCode = IOErrorCode_GENERAL;
751 aMsg = "a general error during transfer command";
752 break;
754 default:
755 ioErrorCode = IOErrorCode_GENERAL;
756 aMsg = "a general error during transfer command";
757 break;
759 cancelCommandExecution(
760 ioErrorCode,
761 generateErrorArguments(aUncPath),
762 xEnv,
763 aMsg,
764 xComProc );
766 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
768 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
769 cancelCommandExecution(
770 ioErrorCode,
771 generateErrorArguments(aUncPath),
772 xEnv,
773 "accessing the root during transfer",
774 xComProc );
776 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
778 aAny <<= InteractiveBadTransferURLException(
779 "bad transfer url",
780 xComProc);
781 cancelCommandExecution( aAny,xEnv );
783 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
784 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
785 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
786 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
787 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
788 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
789 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
790 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
791 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
792 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
794 OUString aMsg(
795 "general error during transfer");
797 switch( minorCode )
799 case FileBase::E_EXIST:
800 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
801 break;
802 case FileBase::E_INVAL: // the format of the parameters was not valid
803 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
804 break;
805 case FileBase::E_NOMEM: // not enough memory for allocating structures
806 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
807 break;
808 case FileBase::E_ACCES: // Permission denied
809 ioErrorCode = IOErrorCode_ACCESS_DENIED;
810 break;
811 case FileBase::E_PERM: // Operation not permitted
812 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
813 break;
814 case FileBase::E_NAMETOOLONG: // File name too long
815 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
816 break;
817 case FileBase::E_NOENT: // No such file or directory
818 ioErrorCode = IOErrorCode_NOT_EXISTING;
819 aMsg = "file/folder does not exist";
820 break;
821 case FileBase::E_ROFS: // Read-only file system<p>
822 ioErrorCode = IOErrorCode_NOT_EXISTING;
823 break;
824 default:
825 ioErrorCode = IOErrorCode_GENERAL;
826 break;
828 cancelCommandExecution(
829 ioErrorCode,
830 generateErrorArguments(aUncPath),
831 xEnv,
832 aMsg,
833 xComProc );
835 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
836 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
838 NameClashException excep;
839 excep.Name = getTitle(aUncPath);
840 excep.Classification = InteractionClassification_ERROR;
841 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
842 excep.Message = "name clash during copy or move";
844 cancelCommandExecution(Any(excep), xEnv);
846 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
847 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
849 UnsupportedNameClashException excep;
850 excep.NameClash = minorCode;
851 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
852 excep.Message = "name clash value not supported during copy or move";
854 cancelCommandExecution(Any(excep), xEnv);
856 else
858 // case TASKHANDLER_NO_ERROR:
859 return;
864 } // end namespace fileaccess
866 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */