Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / file / filglob.cxx
blob15277a2bc8bd00d9628c52af9a636dc6a3029588
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 "filglob.hxx"
21 #include "filerror.hxx"
22 #include "bc.hxx"
23 #include <osl/file.hxx>
24 #include <ucbhelper/cancelcommandexecution.hxx>
25 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
26 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <com/sun/star/ucb/IOErrorCode.hpp>
29 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
30 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
31 #include <com/sun/star/ucb/NameClashException.hpp>
32 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
33 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
34 #include <com/sun/star/beans/PropertyState.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <osl/diagnose.h>
40 #include <rtl/uri.hxx>
41 #include <rtl/ustring.hxx>
42 #include <sal/types.h>
44 using namespace ucbhelper;
45 using namespace osl;
46 using namespace ::com::sun::star;
47 using namespace com::sun::star::task;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::ucb;
53 namespace {
55 Sequence< Any > generateErrorArguments(
56 OUString const & rPhysicalUrl)
58 OUString aResourceName;
59 OUString aResourceType;
60 bool bRemovable = false;
61 bool bResourceName = false;
62 bool bResourceType = false;
63 bool bRemoveProperty = false;
65 if (osl::FileBase::getSystemPathFromFileURL(
66 rPhysicalUrl,
67 aResourceName)
68 == osl::FileBase::E_None)
69 bResourceName = true;
71 // The resource types "folder" (i.e., directory) and
72 // "volume" seem to be
73 // the most interesting when producing meaningful error messages:
74 osl::DirectoryItem aItem;
75 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
76 osl::FileBase::E_None)
78 osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
79 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
80 switch (aStatus.getFileType())
82 case osl::FileStatus::Directory:
83 aResourceType = "folder";
84 bResourceType = true;
85 break;
87 case osl::FileStatus::Volume:
89 aResourceType = "volume";
90 bResourceType = true;
91 osl::VolumeInfo aVolumeInfo(
92 osl_VolumeInfo_Mask_Attributes );
93 if( osl::Directory::getVolumeInfo(
94 rPhysicalUrl,aVolumeInfo ) ==
95 osl::FileBase::E_None )
97 bRemovable = aVolumeInfo.getRemoveableFlag();
98 bRemoveProperty = true;
101 break;
102 case osl::FileStatus::Regular:
103 case osl::FileStatus::Fifo:
104 case osl::FileStatus::Socket:
105 case osl::FileStatus::Link:
106 case osl::FileStatus::Special:
107 case osl::FileStatus::Unknown:
108 // do nothing for now
109 break;
113 Sequence< Any > aArguments( 1 +
114 (bResourceName ? 1 : 0) +
115 (bResourceType ? 1 : 0) +
116 (bRemoveProperty ? 1 : 0) );
117 sal_Int32 i = 0;
118 aArguments[i++]
119 <<= PropertyValue("Uri",
121 makeAny(rPhysicalUrl),
122 PropertyState_DIRECT_VALUE);
123 if (bResourceName)
124 aArguments[i++]
125 <<= PropertyValue("ResourceName",
127 makeAny(aResourceName),
128 PropertyState_DIRECT_VALUE);
129 if (bResourceType)
130 aArguments[i++]
131 <<= PropertyValue("ResourceType",
133 makeAny(aResourceType),
134 PropertyState_DIRECT_VALUE);
135 if (bRemoveProperty)
136 aArguments[i++]
137 <<= PropertyValue("Removable",
139 makeAny(bRemovable),
140 PropertyState_DIRECT_VALUE);
142 return aArguments;
147 namespace fileaccess {
150 bool isChild( const OUString& srcUnqPath,
151 const OUString& dstUnqPath )
153 static const sal_Unicode slash = '/';
154 // Simple lexical comparison
155 sal_Int32 srcL = srcUnqPath.getLength();
156 sal_Int32 dstL = dstUnqPath.getLength();
158 return (
159 ( srcUnqPath == dstUnqPath )
161 ( ( dstL > srcL )
163 dstUnqPath.startsWith(srcUnqPath)
165 ( dstUnqPath[ srcL ] == slash ) )
170 OUString newName(
171 const OUString& aNewPrefix,
172 const OUString& aOldPrefix,
173 const OUString& old_Name )
175 sal_Int32 srcL = aOldPrefix.getLength();
177 return aNewPrefix + old_Name.copy( srcL );
181 OUString getTitle( const OUString& aPath )
183 sal_Int32 lastIndex = aPath.lastIndexOf( '/' );
184 return aPath.copy( lastIndex + 1 );
188 OUString getParentName( const OUString& aFileName )
190 sal_Int32 lastIndex = aFileName.lastIndexOf( '/' );
191 OUString aParent = aFileName.copy( 0,lastIndex );
193 if( aParent.endsWith(":") && aParent.getLength() == 6 )
194 aParent += "/";
196 if ( aParent == "file://" )
197 aParent = "file:///";
199 return aParent;
203 osl::FileBase::RC osl_File_copy( const OUString& strPath,
204 const OUString& strDestPath,
205 bool test )
207 if( test )
209 osl::DirectoryItem aItem;
210 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
211 return osl::FileBase::E_EXIST;
214 return osl::File::copy( strPath,strDestPath );
218 osl::FileBase::RC osl_File_move( const OUString& strPath,
219 const OUString& strDestPath,
220 bool test )
222 if( test )
224 osl::DirectoryItem aItem;
225 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
226 return osl::FileBase::E_EXIST;
229 return osl::File::move( strPath,strDestPath );
232 void throw_handler(
233 sal_Int32 errorCode,
234 sal_Int32 minorCode,
235 const Reference< XCommandEnvironment >& xEnv,
236 const OUString& aUncPath,
237 BaseContent* pContent,
238 bool isHandled )
240 Reference<XCommandProcessor> xComProc(pContent);
241 Any aAny;
242 IOErrorCode ioErrorCode;
244 if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
246 aAny <<= UnsupportedCommandException( OSL_LOG_PREFIX );
247 cancelCommandExecution( aAny,xEnv );
249 else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
250 errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
251 errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
252 errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
253 errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
254 errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT ||
255 errorCode == TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT )
257 IllegalArgumentException excep;
258 excep.ArgumentPosition = 0;
259 cancelCommandExecution(Any(excep), xEnv);
261 else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
263 UnsupportedOpenModeException excep;
264 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
265 cancelCommandExecution( Any(excep),xEnv );
267 else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
268 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
269 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
271 // What to do here?
273 else if(
274 // error in opening file
275 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
276 // error in opening file
277 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
278 // error in opening file
279 errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
280 // error in opening file
281 errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
282 // error in opening file
283 errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
285 switch( minorCode )
287 case FileBase::E_NAMETOOLONG:
288 // pathname was too long
289 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
290 break;
291 case FileBase::E_NXIO:
292 // No such device or address
293 case FileBase::E_NODEV:
294 // No such device
295 ioErrorCode = IOErrorCode_INVALID_DEVICE;
296 break;
297 case FileBase::E_NOTDIR:
298 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
299 break;
300 case FileBase::E_NOENT:
301 // No such file or directory
302 ioErrorCode = IOErrorCode_NOT_EXISTING;
303 break;
304 case FileBase::E_ROFS:
305 // #i4735# handle ROFS transparently as ACCESS_DENIED
306 case FileBase::E_ACCES:
307 case FileBase::E_PERM:
308 // permission denied<P>
309 ioErrorCode = IOErrorCode_ACCESS_DENIED;
310 break;
311 case FileBase::E_ISDIR:
312 // Is a directory<p>
313 ioErrorCode = IOErrorCode_NO_FILE;
314 break;
315 case FileBase::E_NOTREADY:
316 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
317 break;
318 case FileBase::E_MFILE:
319 // too many open files used by the process
320 case FileBase::E_NFILE:
321 // too many open files in the system
322 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
323 break;
324 case FileBase::E_INVAL:
325 // the format of the parameters was not valid
326 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
327 break;
328 case FileBase::E_NOMEM:
329 // not enough memory for allocating structures
330 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
331 break;
332 case FileBase::E_BUSY:
333 // Text file busy
334 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
335 break;
336 case FileBase::E_AGAIN:
337 // Operation would block
338 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
339 break;
340 case FileBase::E_NOLCK: // No record locks available
341 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
342 break;
343 case FileBase::E_NOSYS:
344 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
345 break;
346 case FileBase::E_FAULT: // Bad address
347 case FileBase::E_LOOP: // Too many symbolic links encountered
348 case FileBase::E_NOSPC: // No space left on device
349 case FileBase::E_INTR: // function call was interrupted
350 case FileBase::E_IO: // I/O error
351 case FileBase::E_MULTIHOP: // Multihop attempted
352 case FileBase::E_NOLINK: // Link has been severed
353 default:
354 ioErrorCode = IOErrorCode_GENERAL;
355 break;
358 cancelCommandExecution(
359 ioErrorCode,
360 generateErrorArguments(aUncPath),
361 xEnv,
362 "an error occurred during file opening",
363 xComProc);
365 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
366 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
368 switch( minorCode )
370 case FileBase::E_INVAL:
371 // the format of the parameters was not valid
372 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
373 break;
374 case FileBase::E_NOENT:
375 // the specified path doesn't exist
376 ioErrorCode = IOErrorCode_NOT_EXISTING;
377 break;
378 case FileBase::E_NOTDIR:
379 // the specified path is not a directory
380 ioErrorCode = IOErrorCode_NO_DIRECTORY;
381 break;
382 case FileBase::E_NOMEM:
383 // not enough memory for allocating structures
384 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
385 break;
386 case FileBase::E_ROFS:
387 // #i4735# handle ROFS transparently as ACCESS_DENIED
388 case FileBase::E_ACCES: // permission denied
389 ioErrorCode = IOErrorCode_ACCESS_DENIED;
390 break;
391 case FileBase::E_NOTREADY:
392 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
393 break;
394 case FileBase::E_MFILE:
395 // too many open files used by the process
396 case FileBase::E_NFILE:
397 // too many open files in the system
398 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
399 break;
400 case FileBase::E_NAMETOOLONG:
401 // File name too long
402 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
403 break;
404 case FileBase::E_LOOP:
405 // Too many symbolic links encountered<p>
406 default:
407 ioErrorCode = IOErrorCode_GENERAL;
408 break;
411 cancelCommandExecution(
412 ioErrorCode,
413 generateErrorArguments(aUncPath),
414 xEnv,
415 "an error occurred during opening a directory",
416 xComProc);
418 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
419 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
420 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
421 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
422 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
423 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
425 ioErrorCode = IOErrorCode_UNKNOWN;
426 cancelCommandExecution(
427 ioErrorCode,
428 generateErrorArguments(aUncPath),
429 xEnv,
430 "an error occurred writing or reading from a file",
431 xComProc );
433 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
435 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
436 cancelCommandExecution(
437 ioErrorCode,
438 generateErrorArguments(aUncPath),
439 xEnv,
440 "device full",
441 xComProc);
443 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
444 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
446 switch( minorCode )
448 case FileBase::E_INVAL:
449 // the format of the parameters was not valid
450 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
451 break;
452 case FileBase::E_FBIG:
453 // File too large
454 ioErrorCode = IOErrorCode_CANT_WRITE;
455 break;
456 case FileBase::E_NOSPC:
457 // No space left on device
458 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
459 break;
460 case FileBase::E_NXIO:
461 // No such device or address
462 ioErrorCode = IOErrorCode_INVALID_DEVICE;
463 break;
464 case FileBase::E_NOLINK:
465 // Link has been severed
466 case FileBase::E_ISDIR:
467 // Is a directory
468 ioErrorCode = IOErrorCode_NO_FILE;
469 break;
470 case FileBase::E_AGAIN:
471 // Operation would block
472 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
473 break;
474 case FileBase::E_TIMEDOUT:
475 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
476 break;
477 case FileBase::E_NOLCK: // No record locks available
478 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
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 "an error occurred during opening a file",
493 xComProc);
495 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
496 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
498 Sequence< OUString > aSeq( 1 );
499 aSeq[0] =
500 ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
501 OUStringLiteral("Title") :
502 OUStringLiteral("ContentType");
504 aAny <<= MissingPropertiesException(
505 "a property is missing, necessary to create a content",
506 xComProc,
507 aSeq);
508 cancelCommandExecution(aAny,xEnv);
510 else if( errorCode == TASKHANDLING_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 "there were problems with the filesize",
530 xComProc);
532 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
534 aAny <<=
535 MissingInputStreamException(
536 "the inputstream is missing, necessary to create a content",
537 xComProc);
538 cancelCommandExecution(aAny,xEnv);
540 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
541 // Overwrite = false and file exists
543 NameClashException excep;
544 excep.Name = getTitle(aUncPath);
545 excep.Classification = InteractionClassification_ERROR;
546 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
547 excep.Message = "file exists and overwrite forbidden";
548 cancelCommandExecution( Any(excep), xEnv );
550 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
552 InteractiveAugmentedIOException excep;
553 excep.Code = IOErrorCode_INVALID_CHARACTER;
554 PropertyValue prop;
555 prop.Name = "ResourceName";
556 prop.Handle = -1;
557 OUString aClashingName(
558 rtl::Uri::decode(
559 getTitle(aUncPath),
560 rtl_UriDecodeWithCharset,
561 RTL_TEXTENCODING_UTF8));
562 prop.Value <<= aClashingName;
563 Sequence<Any> seq(1);
564 seq[0] <<= prop;
565 excep.Arguments = seq;
566 excep.Classification = InteractionClassification_ERROR;
567 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
568 excep.Message = "the name contained invalid characters";
569 if(isHandled)
570 throw excep;
571 cancelCommandExecution( Any(excep), xEnv );
572 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
573 // cancelCommandExecution(
574 // ioErrorCode,
575 // generateErrorArguments(aUncPath),
576 // xEnv,
577 // OUString( "the name contained invalid characters"),
578 // xComProc );
580 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
582 NameClashException excep;
583 excep.Name = getTitle(aUncPath);
584 excep.Classification = InteractionClassification_ERROR;
585 excep.Context = xComProc;
586 excep.Message = "folder exists and overwrite forbidden";
587 if(isHandled)
588 throw excep;
589 cancelCommandExecution( Any(excep), xEnv );
590 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
591 // cancelCommandExecution(
592 // ioErrorCode,
593 // generateErrorArguments(aUncPath),
594 // xEnv,
595 // OUString( "the folder exists"),
596 // xComProc );
598 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
599 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
601 switch( minorCode )
603 case FileBase::E_ACCES:
604 ioErrorCode = IOErrorCode_ACCESS_DENIED;
605 break;
606 case FileBase::E_ROFS:
607 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
608 break;
609 case FileBase::E_NAMETOOLONG:
610 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
611 break;
612 default:
613 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
614 break;
616 cancelCommandExecution(
617 ioErrorCode,
618 generateErrorArguments(getParentName(aUncPath)),
619 //TODO! ok to supply physical URL to getParentName()?
620 xEnv,
621 "a folder could not be created",
622 xComProc );
624 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
625 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
626 errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
628 switch( minorCode )
630 case FileBase::E_INVAL: // the format of the parameters was not valid
631 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
632 break;
633 case FileBase::E_NOMEM: // not enough memory for allocating structures
634 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
635 break;
636 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
637 case FileBase::E_ACCES: // permission denied
638 ioErrorCode = IOErrorCode_ACCESS_DENIED;
639 break;
640 case FileBase::E_MFILE: // too many open files used by the process
641 case FileBase::E_NFILE: // too many open files in the system
642 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
643 break;
644 case FileBase::E_NOLINK: // Link has been severed
645 case FileBase::E_NOENT: // No such file or directory
646 ioErrorCode = IOErrorCode_NOT_EXISTING;
647 break;
648 case FileBase::E_NAMETOOLONG: // File name too long
649 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
650 break;
651 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
652 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
653 break;
654 case FileBase::E_LOOP: // Too many symbolic links encountered
655 case FileBase::E_IO: // I/O error
656 case FileBase::E_MULTIHOP: // Multihop attempted
657 case FileBase::E_FAULT: // Bad address
658 case FileBase::E_INTR: // function call was interrupted
659 case FileBase::E_NOSYS: // Function not implemented
660 case FileBase::E_NOSPC: // No space left on device
661 case FileBase::E_NXIO: // No such device or address
662 case FileBase::E_OVERFLOW: // Value too large for defined data type
663 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
664 default:
665 ioErrorCode = IOErrorCode_GENERAL;
666 break;
668 cancelCommandExecution(
669 ioErrorCode,
670 generateErrorArguments(aUncPath),
671 xEnv,
672 "a file status object could not be filled",
673 xComProc );
675 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
676 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
678 switch( minorCode )
680 case FileBase::E_INVAL: // the format of the parameters was not valid
681 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
682 break;
683 case FileBase::E_NOMEM: // not enough memory for allocating structures
684 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
685 break;
686 case FileBase::E_ACCES: // Permission denied
687 ioErrorCode = IOErrorCode_ACCESS_DENIED;
688 break;
689 case FileBase::E_PERM: // Operation not permitted
690 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
691 break;
692 case FileBase::E_NAMETOOLONG: // File name too long
693 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
694 break;
695 case FileBase::E_NOLINK: // Link has been severed
696 case FileBase::E_NOENT: // No such file or directory
697 ioErrorCode = IOErrorCode_NOT_EXISTING;
698 break;
699 case FileBase::E_ISDIR: // Is a directory
700 case FileBase::E_ROFS: // Read-only file system
701 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
702 break;
703 case FileBase::E_BUSY: // Device or resource busy
704 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
705 break;
706 case FileBase::E_FAULT: // Bad address
707 case FileBase::E_LOOP: // Too many symbolic links encountered
708 case FileBase::E_IO: // I/O error
709 case FileBase::E_INTR: // function call was interrupted
710 case FileBase::E_MULTIHOP: // Multihop attempted
711 default:
712 ioErrorCode = IOErrorCode_GENERAL;
713 break;
715 cancelCommandExecution(
716 ioErrorCode,
717 generateErrorArguments(aUncPath),
718 xEnv,
719 "a file or directory could not be deleted",
720 xComProc );
722 else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
723 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
724 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
725 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
726 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
727 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
728 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
729 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
731 OUString aMsg;
732 switch( minorCode )
734 case FileBase::E_NOENT: // No such file or directory
735 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
736 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
737 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
738 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
740 ioErrorCode = IOErrorCode_NOT_EXISTING;
741 aMsg = "source file/folder does not exist";
742 break;
744 else
746 ioErrorCode = IOErrorCode_GENERAL;
747 aMsg = "a general error during transfer command";
748 break;
750 default:
751 ioErrorCode = IOErrorCode_GENERAL;
752 aMsg = "a general error during transfer command";
753 break;
755 cancelCommandExecution(
756 ioErrorCode,
757 generateErrorArguments(aUncPath),
758 xEnv,
759 aMsg,
760 xComProc );
762 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
764 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
765 cancelCommandExecution(
766 ioErrorCode,
767 generateErrorArguments(aUncPath),
768 xEnv,
769 "accessing the root during transfer",
770 xComProc );
772 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
774 aAny <<= InteractiveBadTransferURLException(
775 "bad transfer url",
776 xComProc);
777 cancelCommandExecution( aAny,xEnv );
779 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
780 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
781 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
782 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
783 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
784 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
785 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
786 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
787 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
788 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
790 OUString aMsg(
791 "general error during transfer");
793 switch( minorCode )
795 case FileBase::E_EXIST:
796 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
797 break;
798 case FileBase::E_INVAL: // the format of the parameters was not valid
799 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
800 break;
801 case FileBase::E_NOMEM: // not enough memory for allocating structures
802 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
803 break;
804 case FileBase::E_ACCES: // Permission denied
805 ioErrorCode = IOErrorCode_ACCESS_DENIED;
806 break;
807 case FileBase::E_PERM: // Operation not permitted
808 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
809 break;
810 case FileBase::E_NAMETOOLONG: // File name too long
811 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
812 break;
813 case FileBase::E_NOENT: // No such file or directory
814 ioErrorCode = IOErrorCode_NOT_EXISTING;
815 aMsg = "file/folder does not exist";
816 break;
817 case FileBase::E_ROFS: // Read-only file system<p>
818 ioErrorCode = IOErrorCode_NOT_EXISTING;
819 break;
820 default:
821 ioErrorCode = IOErrorCode_GENERAL;
822 break;
824 cancelCommandExecution(
825 ioErrorCode,
826 generateErrorArguments(aUncPath),
827 xEnv,
828 aMsg,
829 xComProc );
831 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
832 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
834 NameClashException excep;
835 excep.Name = getTitle(aUncPath);
836 excep.Classification = InteractionClassification_ERROR;
837 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
838 excep.Message = "name clash during copy or move";
840 cancelCommandExecution(Any(excep), xEnv);
842 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
843 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
845 UnsupportedNameClashException excep;
846 excep.NameClash = minorCode;
847 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
848 excep.Message = "name clash value not supported during copy or move";
850 cancelCommandExecution(Any(excep), xEnv);
852 else
854 // case TASKHANDLER_NO_ERROR:
855 return;
860 } // end namespace fileaccess
862 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */