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