bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / file / filglob.cxx
blobb9c54218686bbe8e37ed13a6ef5097f863b7a46e
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 "shell.hxx"
23 #include "bc.hxx"
24 #include <osl/file.hxx>
25 #include <vector>
26 #include <ucbhelper/cancelcommandexecution.hxx>
27 #include <com/sun/star/ucb/CommandAbortedException.hpp>
28 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
29 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 #include <com/sun/star/ucb/IOErrorCode.hpp>
32 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
33 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
34 #include <com/sun/star/ucb/NameClashException.hpp>
35 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
36 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
37 #include "com/sun/star/beans/PropertyState.hpp"
38 #include "com/sun/star/beans/PropertyValue.hpp"
39 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
40 #include "com/sun/star/uno/Any.hxx"
41 #include "com/sun/star/uno/Sequence.hxx"
42 #include "osl/diagnose.h"
43 #include "rtl/ustrbuf.hxx"
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(OUString( "Uri"),
125 makeAny(rPhysicalUrl),
126 PropertyState_DIRECT_VALUE);
127 if (bResourceName)
128 aArguments[i++]
129 <<= PropertyValue(OUString( "ResourceName"),
131 makeAny(aResourceName),
132 PropertyState_DIRECT_VALUE);
133 if (bResourceType)
134 aArguments[i++]
135 <<= PropertyValue(OUString( "ResourceType"),
137 makeAny(aResourceType),
138 PropertyState_DIRECT_VALUE);
139 if (bRemoveProperty)
140 aArguments[i++]
141 <<= PropertyValue(OUString( "Removable"),
143 makeAny(bRemovable),
144 PropertyState_DIRECT_VALUE);
146 return aArguments;
152 namespace fileaccess {
155 bool isChild( const OUString& srcUnqPath,
156 const OUString& dstUnqPath )
158 static sal_Unicode slash = '/';
159 // Simple lexical comparison
160 sal_Int32 srcL = srcUnqPath.getLength();
161 sal_Int32 dstL = dstUnqPath.getLength();
163 return (
164 ( srcUnqPath == dstUnqPath )
166 ( ( dstL > srcL )
168 dstUnqPath.startsWith(srcUnqPath)
170 ( dstUnqPath[ srcL ] == slash ) )
175 OUString newName(
176 const OUString& aNewPrefix,
177 const OUString& aOldPrefix,
178 const OUString& old_Name )
180 sal_Int32 srcL = aOldPrefix.getLength();
182 OUString new_Name = old_Name.copy( srcL );
183 new_Name = ( aNewPrefix + new_Name );
184 return new_Name;
188 OUString getTitle( const OUString& aPath )
190 sal_Unicode slash = '/';
191 sal_Int32 lastIndex = aPath.lastIndexOf( slash );
192 return aPath.copy( lastIndex + 1 );
196 OUString getParentName( const OUString& aFileName )
198 sal_Int32 lastIndex = aFileName.lastIndexOf( '/' );
199 OUString aParent = aFileName.copy( 0,lastIndex );
201 if( aParent.endsWith(":") && aParent.getLength() == 6 )
202 aParent += "/";
204 if ( aParent == "file://" )
205 aParent = "file:///";
207 return aParent;
211 osl::FileBase::RC osl_File_copy( const OUString& strPath,
212 const OUString& strDestPath,
213 bool test )
215 if( test )
217 osl::DirectoryItem aItem;
218 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
219 return osl::FileBase::E_EXIST;
222 return osl::File::copy( strPath,strDestPath );
226 osl::FileBase::RC osl_File_move( const OUString& strPath,
227 const OUString& strDestPath,
228 bool test )
230 if( test )
232 osl::DirectoryItem aItem;
233 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
234 return osl::FileBase::E_EXIST;
237 return osl::File::move( strPath,strDestPath );
240 void throw_handler(
241 sal_Int32 errorCode,
242 sal_Int32 minorCode,
243 const Reference< XCommandEnvironment >& xEnv,
244 const OUString& aUncPath,
245 BaseContent* pContent,
246 bool isHandled )
248 Reference<XCommandProcessor> xComProc(pContent);
249 Any aAny;
250 IOErrorCode ioErrorCode;
252 if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
254 aAny <<= UnsupportedCommandException( OSL_LOG_PREFIX );
255 cancelCommandExecution( aAny,xEnv );
257 else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
258 errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
259 errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
260 errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
261 errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
262 errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT ||
263 errorCode == TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT )
265 IllegalArgumentException excep;
266 excep.ArgumentPosition = 0;
267 aAny <<= excep;
268 cancelCommandExecution(
269 aAny,xEnv);
271 else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
273 UnsupportedOpenModeException excep;
274 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
275 aAny <<= excep;
276 cancelCommandExecution( aAny,xEnv );
278 else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
279 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
280 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
282 // What to do here?
284 else if(
285 // error in opening file
286 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
287 // error in opening file
288 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
289 // error in opening file
290 errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
291 // error in opening file
292 errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
293 // error in opening file
294 errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
296 switch( minorCode )
298 case FileBase::E_NAMETOOLONG:
299 // pathname was too long
300 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
301 break;
302 case FileBase::E_NXIO:
303 // No such device or address
304 case FileBase::E_NODEV:
305 // No such device
306 ioErrorCode = IOErrorCode_INVALID_DEVICE;
307 break;
308 case FileBase::E_NOTDIR:
309 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
310 break;
311 case FileBase::E_NOENT:
312 // No such file or directory
313 ioErrorCode = IOErrorCode_NOT_EXISTING;
314 break;
315 case FileBase::E_ROFS:
316 // #i4735# handle ROFS transparently as ACCESS_DENIED
317 case FileBase::E_ACCES:
318 // permission denied<P>
319 ioErrorCode = IOErrorCode_ACCESS_DENIED;
320 break;
321 case FileBase::E_ISDIR:
322 // Is a directory<p>
323 ioErrorCode = IOErrorCode_NO_FILE;
324 break;
325 case FileBase::E_NOTREADY:
326 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
327 break;
328 case FileBase::E_MFILE:
329 // too many open files used by the process
330 case FileBase::E_NFILE:
331 // too many open files in the system
332 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
333 break;
334 case FileBase::E_INVAL:
335 // the format of the parameters was not valid
336 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
337 break;
338 case FileBase::E_NOMEM:
339 // not enough memory for allocating structures
340 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
341 break;
342 case FileBase::E_BUSY:
343 // Text file busy
344 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
345 break;
346 case FileBase::E_AGAIN:
347 // Operation would block
348 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
349 break;
350 case FileBase::E_NOLCK: // No record locks available
351 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
352 break;
354 case FileBase::E_FAULT: // Bad address
355 case FileBase::E_LOOP: // Too many symbolic links encountered
356 case FileBase::E_NOSPC: // No space left on device
357 case FileBase::E_INTR: // function call was interrupted
358 case FileBase::E_IO: // I/O error
359 case FileBase::E_MULTIHOP: // Multihop attempted
360 case FileBase::E_NOLINK: // Link has been severed
361 default:
362 ioErrorCode = IOErrorCode_GENERAL;
363 break;
366 cancelCommandExecution(
367 ioErrorCode,
368 generateErrorArguments(aUncPath),
369 xEnv,
370 OUString( "an error occurred during file opening"),
371 xComProc);
373 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
374 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
376 switch( minorCode )
378 case FileBase::E_INVAL:
379 // the format of the parameters was not valid
380 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
381 break;
382 case FileBase::E_NOENT:
383 // the specified path doesn't exist
384 ioErrorCode = IOErrorCode_NOT_EXISTING;
385 break;
386 case FileBase::E_NOTDIR:
387 // the specified path is not an directory
388 ioErrorCode = IOErrorCode_NO_DIRECTORY;
389 break;
390 case FileBase::E_NOMEM:
391 // not enough memory for allocating structures
392 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
393 break;
394 case FileBase::E_ROFS:
395 // #i4735# handle ROFS transparently as ACCESS_DENIED
396 case FileBase::E_ACCES: // permission denied
397 ioErrorCode = IOErrorCode_ACCESS_DENIED;
398 break;
399 case FileBase::E_NOTREADY:
400 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
401 break;
402 case FileBase::E_MFILE:
403 // too many open files used by the process
404 case FileBase::E_NFILE:
405 // too many open files in the system
406 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
407 break;
408 case FileBase::E_NAMETOOLONG:
409 // File name too long
410 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
411 break;
412 case FileBase::E_LOOP:
413 // Too many symbolic links encountered<p>
414 default:
415 ioErrorCode = IOErrorCode_GENERAL;
416 break;
419 cancelCommandExecution(
420 ioErrorCode,
421 generateErrorArguments(aUncPath),
422 xEnv,
423 OUString( "an error occurred during opening a directory"),
424 xComProc);
426 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
427 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
428 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
429 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
430 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
431 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
433 ioErrorCode = IOErrorCode_UNKNOWN;
434 cancelCommandExecution(
435 ioErrorCode,
436 generateErrorArguments(aUncPath),
437 xEnv,
438 OUString( "an error occurred writing or reading from a file"),
439 xComProc );
441 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
443 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
444 cancelCommandExecution(
445 ioErrorCode,
446 generateErrorArguments(aUncPath),
447 xEnv,
448 OUString( "device full"),
449 xComProc);
451 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
452 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
454 switch( minorCode )
456 case FileBase::E_INVAL:
457 // the format of the parameters was not valid
458 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
459 break;
460 case FileBase::E_FBIG:
461 // File too large
462 ioErrorCode = IOErrorCode_CANT_WRITE;
463 break;
464 case FileBase::E_NOSPC:
465 // No space left on device
466 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
467 break;
468 case FileBase::E_NXIO:
469 // No such device or address
470 ioErrorCode = IOErrorCode_INVALID_DEVICE;
471 break;
472 case FileBase::E_NOLINK:
473 // Link has been severed
474 case FileBase::E_ISDIR:
475 // Is a directory
476 ioErrorCode = IOErrorCode_NO_FILE;
477 break;
478 case FileBase::E_AGAIN:
479 // Operation would block
480 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
481 break;
482 case FileBase::E_TIMEDOUT:
483 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
484 break;
485 case FileBase::E_NOLCK: // No record locks available
486 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
487 break;
488 case FileBase::E_IO: // I/O error
489 case FileBase::E_BADF: // Bad file
490 case FileBase::E_FAULT: // Bad address
491 case FileBase::E_INTR: // function call was interrupted
492 default:
493 ioErrorCode = IOErrorCode_GENERAL;
494 break;
496 cancelCommandExecution(
497 ioErrorCode,
498 generateErrorArguments(aUncPath),
499 xEnv,
500 OUString( "an error occurred during opening a file"),
501 xComProc);
503 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
504 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
506 Sequence< OUString > aSeq( 1 );
507 aSeq[0] =
508 ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
509 OUString("Title") :
510 OUString("ContentType");
512 aAny <<= MissingPropertiesException(
513 OUString( "a property is missing necessary"
514 "to create a content"),
515 xComProc,
516 aSeq);
517 cancelCommandExecution(aAny,xEnv);
519 else if( errorCode == TASKHANDLING_FILESIZE_FOR_WRITE )
521 switch( minorCode )
523 case FileBase::E_INVAL:
524 // the format of the parameters was not valid
525 case FileBase::E_OVERFLOW:
526 // The resulting file offset would be a value which cannot
527 // be represented correctly for regular files
528 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
529 break;
530 default:
531 ioErrorCode = IOErrorCode_GENERAL;
532 break;
534 cancelCommandExecution(
535 ioErrorCode,
536 generateErrorArguments(aUncPath),
537 xEnv,
538 OUString( "there were problems with the filesize"),
539 xComProc);
541 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
543 aAny <<=
544 MissingInputStreamException(
545 OUString( "the inputstream is missing necessary"
546 "to create a content"),
547 xComProc);
548 cancelCommandExecution(aAny,xEnv);
550 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
551 // Overwrite = false and file exists
553 NameClashException excep;
554 excep.Name = getTitle(aUncPath);
555 excep.Classification = InteractionClassification_ERROR;
556 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
557 excep.Message = "file exists and overwrite forbidden";
558 aAny <<= excep;
559 cancelCommandExecution( aAny,xEnv );
561 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
563 InteractiveAugmentedIOException excep;
564 excep.Code = IOErrorCode_INVALID_CHARACTER;
565 PropertyValue prop;
566 prop.Name = "ResourceName";
567 prop.Handle = -1;
568 OUString m_aClashingName(
569 rtl::Uri::decode(
570 getTitle(aUncPath),
571 rtl_UriDecodeWithCharset,
572 RTL_TEXTENCODING_UTF8));
573 prop.Value <<= m_aClashingName;
574 Sequence<Any> seq(1);
575 seq[0] <<= prop;
576 excep.Arguments = seq;
577 excep.Classification = InteractionClassification_ERROR;
578 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
579 excep.Message = "the name contained invalid characters";
580 if(isHandled)
581 throw excep;
582 else {
583 aAny <<= excep;
584 cancelCommandExecution( aAny,xEnv );
586 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
587 // cancelCommandExecution(
588 // ioErrorCode,
589 // generateErrorArguments(aUncPath),
590 // xEnv,
591 // OUString( "the name contained invalid characters"),
592 // xComProc );
594 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
596 NameClashException excep;
597 excep.Name = getTitle(aUncPath);
598 excep.Classification = InteractionClassification_ERROR;
599 excep.Context = xComProc;
600 excep.Message = "folder exists and overwrite forbidden";
601 if(isHandled)
602 throw excep;
603 else {
604 aAny <<= excep;
605 cancelCommandExecution( aAny,xEnv );
607 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
608 // cancelCommandExecution(
609 // ioErrorCode,
610 // generateErrorArguments(aUncPath),
611 // xEnv,
612 // OUString( "the folder exists"),
613 // xComProc );
615 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
616 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
618 switch( minorCode )
620 case FileBase::E_ACCES:
621 ioErrorCode = IOErrorCode_ACCESS_DENIED;
622 break;
623 case FileBase::E_ROFS:
624 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
625 break;
626 case FileBase::E_NAMETOOLONG:
627 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
628 break;
629 default:
630 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
631 break;
633 cancelCommandExecution(
634 ioErrorCode,
635 generateErrorArguments(getParentName(aUncPath)),
636 //TODO! ok to supply physical URL to getParentName()?
637 xEnv,
638 OUString( "a folder could not be created"),
639 xComProc );
641 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
642 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
643 errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
645 switch( minorCode )
647 case FileBase::E_INVAL: // the format of the parameters was not valid
648 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
649 break;
650 case FileBase::E_NOMEM: // not enough memory for allocating structures
651 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
652 break;
653 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
654 case FileBase::E_ACCES: // permission denied
655 ioErrorCode = IOErrorCode_ACCESS_DENIED;
656 break;
657 case FileBase::E_MFILE: // too many open files used by the process
658 case FileBase::E_NFILE: // too many open files in the system
659 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
660 break;
661 case FileBase::E_NOLINK: // Link has been severed
662 case FileBase::E_NOENT: // No such file or directory
663 ioErrorCode = IOErrorCode_NOT_EXISTING;
664 break;
665 case FileBase::E_NAMETOOLONG: // File name too long
666 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
667 break;
668 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
669 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
670 break;
671 case FileBase::E_LOOP: // Too many symbolic links encountered
672 case FileBase::E_IO: // I/O error
673 case FileBase::E_MULTIHOP: // Multihop attempted
674 case FileBase::E_FAULT: // Bad address
675 case FileBase::E_INTR: // function call was interrupted
676 case FileBase::E_NOSYS: // Function not implemented
677 case FileBase::E_NOSPC: // No space left on device
678 case FileBase::E_NXIO: // No such device or address
679 case FileBase::E_OVERFLOW: // Value too large for defined data type
680 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
681 default:
682 ioErrorCode = IOErrorCode_GENERAL;
683 break;
685 cancelCommandExecution(
686 ioErrorCode,
687 generateErrorArguments(aUncPath),
688 xEnv,
689 OUString( "a file status object could not be filled"),
690 xComProc );
692 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
693 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
695 switch( minorCode )
697 case FileBase::E_INVAL: // the format of the parameters was not valid
698 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
699 break;
700 case FileBase::E_NOMEM: // not enough memory for allocating structures
701 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
702 break;
703 case FileBase::E_ACCES: // Permission denied
704 ioErrorCode = IOErrorCode_ACCESS_DENIED;
705 break;
706 case FileBase::E_PERM: // Operation not permitted
707 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
708 break;
709 case FileBase::E_NAMETOOLONG: // File name too long
710 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
711 break;
712 case FileBase::E_NOLINK: // Link has been severed
713 case FileBase::E_NOENT: // No such file or directory
714 ioErrorCode = IOErrorCode_NOT_EXISTING;
715 break;
716 case FileBase::E_ISDIR: // Is a directory
717 case FileBase::E_ROFS: // Read-only file system
718 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
719 break;
720 case FileBase::E_BUSY: // Device or resource busy
721 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
722 break;
723 case FileBase::E_FAULT: // Bad address
724 case FileBase::E_LOOP: // Too many symbolic links encountered
725 case FileBase::E_IO: // I/O error
726 case FileBase::E_INTR: // function call was interrupted
727 case FileBase::E_MULTIHOP: // Multihop attempted
728 default:
729 ioErrorCode = IOErrorCode_GENERAL;
730 break;
732 cancelCommandExecution(
733 ioErrorCode,
734 generateErrorArguments(aUncPath),
735 xEnv,
736 OUString( "a file or directory could not be deleted"),
737 xComProc );
739 else 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 ||
743 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
744 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
745 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
746 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
748 OUString aMsg;
749 switch( minorCode )
751 case FileBase::E_NOENT: // No such file or directory
752 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
753 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
754 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
755 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
757 ioErrorCode = IOErrorCode_NOT_EXISTING;
758 aMsg = "source file/folder does not exist";
759 break;
761 else
763 ioErrorCode = IOErrorCode_GENERAL;
764 aMsg = "a general error during transfer command";
765 break;
767 default:
768 ioErrorCode = IOErrorCode_GENERAL;
769 aMsg = "a general error during transfer command";
770 break;
772 cancelCommandExecution(
773 ioErrorCode,
774 generateErrorArguments(aUncPath),
775 xEnv,
776 aMsg,
777 xComProc );
779 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
781 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
782 cancelCommandExecution(
783 ioErrorCode,
784 generateErrorArguments(aUncPath),
785 xEnv,
786 OUString( "accessing the root during transfer"),
787 xComProc );
789 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
791 aAny <<=
792 InteractiveBadTransferURLException(
793 OUString( "bad transfer url"),
794 xComProc);
795 cancelCommandExecution( aAny,xEnv );
797 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
798 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
799 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
800 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
801 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
802 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
803 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
804 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
805 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
806 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
808 OUString aMsg(
809 "general error during transfer");
811 switch( minorCode )
813 case FileBase::E_EXIST:
814 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
815 break;
816 case FileBase::E_INVAL: // the format of the parameters was not valid
817 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
818 break;
819 case FileBase::E_NOMEM: // not enough memory for allocating structures
820 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
821 break;
822 case FileBase::E_ACCES: // Permission denied
823 ioErrorCode = IOErrorCode_ACCESS_DENIED;
824 break;
825 case FileBase::E_PERM: // Operation not permitted
826 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
827 break;
828 case FileBase::E_NAMETOOLONG: // File name too long
829 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
830 break;
831 case FileBase::E_NOENT: // No such file or directory
832 ioErrorCode = IOErrorCode_NOT_EXISTING;
833 aMsg = "file/folder does not exist";
834 break;
835 case FileBase::E_ROFS: // Read-only file system<p>
836 ioErrorCode = IOErrorCode_NOT_EXISTING;
837 break;
838 default:
839 ioErrorCode = IOErrorCode_GENERAL;
840 break;
842 cancelCommandExecution(
843 ioErrorCode,
844 generateErrorArguments(aUncPath),
845 xEnv,
846 aMsg,
847 xComProc );
849 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
850 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
852 NameClashException excep;
853 excep.Name = getTitle(aUncPath);
854 excep.Classification = InteractionClassification_ERROR;
855 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
856 excep.Message = "name clash during copy or move";
857 aAny <<= excep;
859 cancelCommandExecution(aAny,xEnv);
861 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
862 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
864 UnsupportedNameClashException excep;
865 excep.NameClash = minorCode;
866 excep.Context = Reference<XInterface>( xComProc, UNO_QUERY );
867 excep.Message = "name clash value not supported during copy or move";
869 aAny <<= excep;
870 cancelCommandExecution(aAny,xEnv);
872 else
874 // case TASKHANDLER_NO_ERROR:
875 return;
880 } // end namespace fileaccess
882 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */