Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / file / filglob.cxx
blobacf69f2f6857c3cb104eb5e2704c2285df4f8228
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 <stdio.h>
21 #include "filglob.hxx"
22 #include "filerror.hxx"
23 #include "shell.hxx"
24 #include "bc.hxx"
25 #include <osl/file.hxx>
26 #include <vector>
27 #include <ucbhelper/cancelcommandexecution.hxx>
28 #include <com/sun/star/ucb/CommandAbortedException.hpp>
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/ustrbuf.hxx"
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 rtl::OUString const & rPhysicalUrl)
63 rtl::OUString aResourceName;
64 rtl::OUString aResourceType;
65 sal_Bool bRemovable;
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 = rtl::OUString( "folder");
89 bResourceType = true;
90 break;
92 case osl::FileStatus::Volume:
94 aResourceType = rtl::OUString( "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 sal_Int32 i = 0;
123 aArguments[i++]
124 <<= PropertyValue(rtl::OUString( "Uri"),
126 makeAny(rPhysicalUrl),
127 PropertyState_DIRECT_VALUE);
128 if (bResourceName)
129 aArguments[i++]
130 <<= PropertyValue(rtl::OUString( "ResourceName"),
132 makeAny(aResourceName),
133 PropertyState_DIRECT_VALUE);
134 if (bResourceType)
135 aArguments[i++]
136 <<= PropertyValue(rtl::OUString( "ResourceType"),
138 makeAny(aResourceType),
139 PropertyState_DIRECT_VALUE);
140 if (bRemoveProperty)
141 aArguments[i++]
142 <<= PropertyValue(rtl::OUString( "Removable"),
144 makeAny(bRemovable),
145 PropertyState_DIRECT_VALUE);
147 return aArguments;
153 namespace fileaccess {
156 sal_Bool isChild( const rtl::OUString& srcUnqPath,
157 const rtl::OUString& dstUnqPath )
159 static sal_Unicode slash = '/';
160 // Simple lexical comparison
161 sal_Int32 srcL = srcUnqPath.getLength();
162 sal_Int32 dstL = dstUnqPath.getLength();
164 return (
165 ( srcUnqPath == dstUnqPath )
167 ( ( dstL > srcL )
169 ( srcUnqPath.compareTo( dstUnqPath, srcL ) == 0 )
171 ( dstUnqPath[ srcL ] == slash ) )
176 rtl::OUString newName(
177 const rtl::OUString& aNewPrefix,
178 const rtl::OUString& aOldPrefix,
179 const rtl::OUString& old_Name )
181 sal_Int32 srcL = aOldPrefix.getLength();
183 rtl::OUString new_Name = old_Name.copy( srcL );
184 new_Name = ( aNewPrefix + new_Name );
185 return new_Name;
189 rtl::OUString getTitle( const rtl::OUString& aPath )
191 sal_Unicode slash = '/';
192 sal_Int32 lastIndex = aPath.lastIndexOf( slash );
193 return aPath.copy( lastIndex + 1 );
197 rtl::OUString getParentName( const rtl::OUString& aFileName )
199 sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') );
200 rtl::OUString aParent = aFileName.copy( 0,lastIndex );
202 if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 )
203 aParent += rtl::OUString("/");
205 if ( aParent == "file://" )
206 aParent = rtl::OUString("file:///");
208 return aParent;
212 osl::FileBase::RC osl_File_copy( const rtl::OUString& strPath,
213 const rtl::OUString& strDestPath,
214 sal_Bool test )
216 if( test )
218 osl::DirectoryItem aItem;
219 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
220 return osl::FileBase::E_EXIST;
223 return osl::File::copy( strPath,strDestPath );
227 osl::FileBase::RC osl_File_move( const rtl::OUString& strPath,
228 const rtl::OUString& strDestPath,
229 sal_Bool test )
231 if( test )
233 osl::DirectoryItem aItem;
234 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
235 return osl::FileBase::E_EXIST;
238 return osl::File::move( strPath,strDestPath );
241 void throw_handler(
242 sal_Int32 errorCode,
243 sal_Int32 minorCode,
244 const Reference< XCommandEnvironment >& xEnv,
245 const rtl::OUString& aUncPath,
246 BaseContent* pContent,
247 bool isHandled )
249 Reference<XCommandProcessor> xComProc(pContent);
250 Any aAny;
251 IOErrorCode ioErrorCode;
253 if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
255 aAny <<= UnsupportedCommandException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >() );
256 cancelCommandExecution( aAny,xEnv );
258 else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
259 errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
260 errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
261 errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
262 errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
263 errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT ||
264 errorCode == TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT )
266 IllegalArgumentException excep;
267 excep.ArgumentPosition = 0;
268 aAny <<= excep;
269 cancelCommandExecution(
270 aAny,xEnv);
272 else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
274 UnsupportedOpenModeException excep;
275 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
276 aAny <<= excep;
277 cancelCommandExecution( aAny,xEnv );
279 else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
280 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
281 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
283 // What to do here?
285 else if(
286 // error in opening file
287 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
288 // error in opening file
289 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
290 // error in opening file
291 errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
292 // error in opening file
293 errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
294 // error in opening file
295 errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
297 switch( minorCode )
299 case FileBase::E_NAMETOOLONG:
300 // pathname was too long
301 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
302 break;
303 case FileBase::E_NXIO:
304 // No such device or address
305 case FileBase::E_NODEV:
306 // No such device
307 ioErrorCode = IOErrorCode_INVALID_DEVICE;
308 break;
309 case FileBase::E_NOTDIR:
310 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
311 break;
312 case FileBase::E_NOENT:
313 // No such file or directory
314 ioErrorCode = IOErrorCode_NOT_EXISTING;
315 break;
316 case FileBase::E_ROFS:
317 // #i4735# handle ROFS transparently as ACCESS_DENIED
318 case FileBase::E_ACCES:
319 // permission denied<P>
320 ioErrorCode = IOErrorCode_ACCESS_DENIED;
321 break;
322 case FileBase::E_ISDIR:
323 // Is a directory<p>
324 ioErrorCode = IOErrorCode_NO_FILE;
325 break;
326 case FileBase::E_NOTREADY:
327 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
328 break;
329 case FileBase::E_MFILE:
330 // too many open files used by the process
331 case FileBase::E_NFILE:
332 // too many open files in the system
333 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
334 break;
335 case FileBase::E_INVAL:
336 // the format of the parameters was not valid
337 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
338 break;
339 case FileBase::E_NOMEM:
340 // not enough memory for allocating structures
341 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
342 break;
343 case FileBase::E_BUSY:
344 // Text file busy
345 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
346 break;
347 case FileBase::E_AGAIN:
348 // Operation would block
349 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
350 break;
351 case FileBase::E_NOLCK: // No record locks available
352 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
353 break;
355 case FileBase::E_FAULT: // Bad address
356 case FileBase::E_LOOP: // Too many symbolic links encountered
357 case FileBase::E_NOSPC: // No space left on device
358 case FileBase::E_INTR: // function call was interrupted
359 case FileBase::E_IO: // I/O error
360 case FileBase::E_MULTIHOP: // Multihop attempted
361 case FileBase::E_NOLINK: // Link has been severed
362 default:
363 ioErrorCode = IOErrorCode_GENERAL;
364 break;
367 cancelCommandExecution(
368 ioErrorCode,
369 generateErrorArguments(aUncPath),
370 xEnv,
371 rtl::OUString( "an error occurred during file opening"),
372 xComProc);
374 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
375 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
377 switch( minorCode )
379 case FileBase::E_INVAL:
380 // the format of the parameters was not valid
381 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
382 break;
383 case FileBase::E_NOENT:
384 // the specified path doesn't exist
385 ioErrorCode = IOErrorCode_NOT_EXISTING;
386 break;
387 case FileBase::E_NOTDIR:
388 // the specified path is not an directory
389 ioErrorCode = IOErrorCode_NO_DIRECTORY;
390 break;
391 case FileBase::E_NOMEM:
392 // not enough memory for allocating structures
393 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
394 break;
395 case FileBase::E_ROFS:
396 // #i4735# handle ROFS transparently as ACCESS_DENIED
397 case FileBase::E_ACCES: // permission denied
398 ioErrorCode = IOErrorCode_ACCESS_DENIED;
399 break;
400 case FileBase::E_NOTREADY:
401 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
402 break;
403 case FileBase::E_MFILE:
404 // too many open files used by the process
405 case FileBase::E_NFILE:
406 // too many open files in the system
407 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
408 break;
409 case FileBase::E_NAMETOOLONG:
410 // File name too long
411 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
412 break;
413 case FileBase::E_LOOP:
414 // Too many symbolic links encountered<p>
415 default:
416 ioErrorCode = IOErrorCode_GENERAL;
417 break;
420 cancelCommandExecution(
421 ioErrorCode,
422 generateErrorArguments(aUncPath),
423 xEnv,
424 rtl::OUString( "an error occurred during opening a directory"),
425 xComProc);
427 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
428 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
429 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
430 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
431 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
432 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
434 ioErrorCode = IOErrorCode_UNKNOWN;
435 cancelCommandExecution(
436 ioErrorCode,
437 generateErrorArguments(aUncPath),
438 xEnv,
439 rtl::OUString( "an error occurred writing or reading from a file"),
440 xComProc );
442 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
444 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
445 cancelCommandExecution(
446 ioErrorCode,
447 generateErrorArguments(aUncPath),
448 xEnv,
449 rtl::OUString( "device full"),
450 xComProc);
452 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
453 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
455 switch( minorCode )
457 case FileBase::E_INVAL:
458 // the format of the parameters was not valid
459 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
460 break;
461 case FileBase::E_FBIG:
462 // File too large
463 ioErrorCode = IOErrorCode_CANT_WRITE;
464 break;
465 case FileBase::E_NOSPC:
466 // No space left on device
467 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
468 break;
469 case FileBase::E_NXIO:
470 // No such device or address
471 ioErrorCode = IOErrorCode_INVALID_DEVICE;
472 break;
473 case FileBase::E_NOLINK:
474 // Link has been severed
475 case FileBase::E_ISDIR:
476 // Is a directory
477 ioErrorCode = IOErrorCode_NO_FILE;
478 break;
479 case FileBase::E_AGAIN:
480 // Operation would block
481 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
482 break;
483 case FileBase::E_TIMEDOUT:
484 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
485 break;
486 case FileBase::E_NOLCK: // No record locks available
487 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
488 break;
489 case FileBase::E_IO: // I/O error
490 case FileBase::E_BADF: // Bad file
491 case FileBase::E_FAULT: // Bad address
492 case FileBase::E_INTR: // function call was interrupted
493 default:
494 ioErrorCode = IOErrorCode_GENERAL;
495 break;
497 cancelCommandExecution(
498 ioErrorCode,
499 generateErrorArguments(aUncPath),
500 xEnv,
501 rtl::OUString( "an error occurred during opening a file"),
502 xComProc);
504 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
505 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
507 Sequence< ::rtl::OUString > aSeq( 1 );
508 aSeq[0] =
509 ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
510 rtl::OUString("Title") :
511 rtl::OUString("ContentType");
513 aAny <<= MissingPropertiesException(
514 rtl::OUString( "a property is missing necessary"
515 "to create a content"),
516 xComProc,
517 aSeq);
518 cancelCommandExecution(aAny,xEnv);
520 else if( errorCode == TASKHANDLING_FILESIZE_FOR_WRITE )
522 switch( minorCode )
524 case FileBase::E_INVAL:
525 // the format of the parameters was not valid
526 case FileBase::E_OVERFLOW:
527 // The resulting file offset would be a value which cannot
528 // be represented correctly for regular files
529 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
530 break;
531 default:
532 ioErrorCode = IOErrorCode_GENERAL;
533 break;
535 cancelCommandExecution(
536 ioErrorCode,
537 generateErrorArguments(aUncPath),
538 xEnv,
539 rtl::OUString( "there were problems with the filesize"),
540 xComProc);
542 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
544 Reference<XInterface> xContext(xComProc,UNO_QUERY);
545 aAny <<=
546 MissingInputStreamException(
547 rtl::OUString( "the inputstream is missing necessary"
548 "to create a content"),
549 xContext);
550 cancelCommandExecution(aAny,xEnv);
552 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
553 // Overwrite = false and file exists
555 NameClashException excep;
556 excep.Name = getTitle(aUncPath);
557 excep.Classification = InteractionClassification_ERROR;
558 Reference<XInterface> xContext(xComProc,UNO_QUERY);
559 excep.Context = xContext;
560 excep.Message = rtl::OUString( "file exists and overwrite forbidden");
561 aAny <<= excep;
562 cancelCommandExecution( aAny,xEnv );
564 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
566 InteractiveAugmentedIOException excep;
567 excep.Code = IOErrorCode_INVALID_CHARACTER;
568 PropertyValue prop;
569 prop.Name = rtl::OUString("ResourceName");
570 prop.Handle = -1;
571 rtl::OUString m_aClashingName(
572 rtl::Uri::decode(
573 getTitle(aUncPath),
574 rtl_UriDecodeWithCharset,
575 RTL_TEXTENCODING_UTF8));
576 prop.Value <<= m_aClashingName;
577 Sequence<Any> seq(1);
578 seq[0] <<= prop;
579 excep.Arguments = seq;
580 excep.Classification = InteractionClassification_ERROR;
581 Reference<XInterface> xContext(xComProc,UNO_QUERY);
582 excep.Context = xContext;
583 excep.Message = rtl::OUString( "the name contained invalid characters");
584 if(isHandled)
585 throw excep;
586 else {
587 aAny <<= excep;
588 cancelCommandExecution( aAny,xEnv );
590 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
591 // cancelCommandExecution(
592 // ioErrorCode,
593 // generateErrorArguments(aUncPath),
594 // xEnv,
595 // rtl::OUString( "the name contained invalid characters"),
596 // xComProc );
598 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
600 NameClashException excep;
601 excep.Name = getTitle(aUncPath);
602 excep.Classification = InteractionClassification_ERROR;
603 Reference<XInterface> xContext(xComProc,UNO_QUERY);
604 excep.Context = xContext;
605 excep.Message = rtl::OUString( "folder exists and overwrite forbidden");
606 if(isHandled)
607 throw excep;
608 else {
609 aAny <<= excep;
610 cancelCommandExecution( aAny,xEnv );
612 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
613 // cancelCommandExecution(
614 // ioErrorCode,
615 // generateErrorArguments(aUncPath),
616 // xEnv,
617 // rtl::OUString( "the folder exists"),
618 // xComProc );
620 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
621 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
623 switch( minorCode )
625 case FileBase::E_ACCES:
626 ioErrorCode = IOErrorCode_ACCESS_DENIED;
627 break;
628 case FileBase::E_ROFS:
629 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
630 break;
631 case FileBase::E_NAMETOOLONG:
632 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
633 break;
634 default:
635 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
636 break;
638 cancelCommandExecution(
639 ioErrorCode,
640 generateErrorArguments(getParentName(aUncPath)),
641 //TODO! ok to supply physical URL to getParentName()?
642 xEnv,
643 rtl::OUString( "a folder could not be created"),
644 xComProc );
646 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
647 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
648 errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
650 switch( minorCode )
652 case FileBase::E_INVAL: // the format of the parameters was not valid
653 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
654 break;
655 case FileBase::E_NOMEM: // not enough memory for allocating structures
656 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
657 break;
658 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
659 case FileBase::E_ACCES: // permission denied
660 ioErrorCode = IOErrorCode_ACCESS_DENIED;
661 break;
662 case FileBase::E_MFILE: // too many open files used by the process
663 case FileBase::E_NFILE: // too many open files in the system
664 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
665 break;
666 case FileBase::E_NOLINK: // Link has been severed
667 case FileBase::E_NOENT: // No such file or directory
668 ioErrorCode = IOErrorCode_NOT_EXISTING;
669 break;
670 case FileBase::E_NAMETOOLONG: // File name too long
671 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
672 break;
673 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
674 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
675 break;
676 case FileBase::E_LOOP: // Too many symbolic links encountered
677 case FileBase::E_IO: // I/O error
678 case FileBase::E_MULTIHOP: // Multihop attempted
679 case FileBase::E_FAULT: // Bad address
680 case FileBase::E_INTR: // function call was interrupted
681 case FileBase::E_NOSYS: // Function not implemented
682 case FileBase::E_NOSPC: // No space left on device
683 case FileBase::E_NXIO: // No such device or address
684 case FileBase::E_OVERFLOW: // Value too large for defined data type
685 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
686 default:
687 ioErrorCode = IOErrorCode_GENERAL;
688 break;
690 cancelCommandExecution(
691 ioErrorCode,
692 generateErrorArguments(aUncPath),
693 xEnv,
694 rtl::OUString( "a file status object could not be filled"),
695 xComProc );
697 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
698 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
700 switch( minorCode )
702 case FileBase::E_INVAL: // the format of the parameters was not valid
703 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
704 break;
705 case FileBase::E_NOMEM: // not enough memory for allocating structures
706 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
707 break;
708 case FileBase::E_ACCES: // Permission denied
709 ioErrorCode = IOErrorCode_ACCESS_DENIED;
710 break;
711 case FileBase::E_PERM: // Operation not permitted
712 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
713 break;
714 case FileBase::E_NAMETOOLONG: // File name too long
715 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
716 break;
717 case FileBase::E_NOLINK: // Link has been severed
718 case FileBase::E_NOENT: // No such file or directory
719 ioErrorCode = IOErrorCode_NOT_EXISTING;
720 break;
721 case FileBase::E_ISDIR: // Is a directory
722 case FileBase::E_ROFS: // Read-only file system
723 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
724 break;
725 case FileBase::E_BUSY: // Device or resource busy
726 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
727 break;
728 case FileBase::E_FAULT: // Bad address
729 case FileBase::E_LOOP: // Too many symbolic links encountered
730 case FileBase::E_IO: // I/O error
731 case FileBase::E_INTR: // function call was interrupted
732 case FileBase::E_MULTIHOP: // Multihop attempted
733 default:
734 ioErrorCode = IOErrorCode_GENERAL;
735 break;
737 cancelCommandExecution(
738 ioErrorCode,
739 generateErrorArguments(aUncPath),
740 xEnv,
741 rtl::OUString( "a file or directory could not be deleted"),
742 xComProc );
744 else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
745 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
746 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
747 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
748 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
749 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
750 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
751 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
753 rtl::OUString aMsg;
754 switch( minorCode )
756 case FileBase::E_NOENT: // No such file or directory
757 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
758 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
759 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
760 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
762 ioErrorCode = IOErrorCode_NOT_EXISTING;
763 aMsg = rtl::OUString( "source file/folder does not exist");
764 break;
766 else
768 ioErrorCode = IOErrorCode_GENERAL;
769 aMsg = rtl::OUString( "a general error during transfer command");
770 break;
772 default:
773 ioErrorCode = IOErrorCode_GENERAL;
774 aMsg = rtl::OUString( "a general error during transfer command");
775 break;
777 cancelCommandExecution(
778 ioErrorCode,
779 generateErrorArguments(aUncPath),
780 xEnv,
781 aMsg,
782 xComProc );
784 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
786 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
787 cancelCommandExecution(
788 ioErrorCode,
789 generateErrorArguments(aUncPath),
790 xEnv,
791 rtl::OUString( "accessing the root during transfer"),
792 xComProc );
794 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
796 Reference<XInterface> xContext(xComProc,UNO_QUERY);
798 aAny <<=
799 InteractiveBadTransferURLException(
800 rtl::OUString( "bad tranfer url"),
801 xContext);
802 cancelCommandExecution( aAny,xEnv );
804 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
805 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
806 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
807 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
808 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
809 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
810 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
811 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
812 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
813 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
815 rtl::OUString aMsg(
816 "general error during transfer");
818 switch( minorCode )
820 case FileBase::E_EXIST:
821 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
822 break;
823 case FileBase::E_INVAL: // the format of the parameters was not valid
824 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
825 break;
826 case FileBase::E_NOMEM: // not enough memory for allocating structures
827 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
828 break;
829 case FileBase::E_ACCES: // Permission denied
830 ioErrorCode = IOErrorCode_ACCESS_DENIED;
831 break;
832 case FileBase::E_PERM: // Operation not permitted
833 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
834 break;
835 case FileBase::E_NAMETOOLONG: // File name too long
836 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
837 break;
838 case FileBase::E_NOENT: // No such file or directory
839 ioErrorCode = IOErrorCode_NOT_EXISTING;
840 aMsg = rtl::OUString( "file/folder does not exist");
841 break;
842 case FileBase::E_ROFS: // Read-only file system<p>
843 ioErrorCode = IOErrorCode_NOT_EXISTING;
844 break;
845 default:
846 ioErrorCode = IOErrorCode_GENERAL;
847 break;
849 cancelCommandExecution(
850 ioErrorCode,
851 generateErrorArguments(aUncPath),
852 xEnv,
853 aMsg,
854 xComProc );
856 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
857 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
859 NameClashException excep;
860 excep.Name = getTitle(aUncPath);
861 excep.Classification = InteractionClassification_ERROR;
862 Reference<XInterface> xContext(xComProc,UNO_QUERY);
863 excep.Context = xContext;
864 excep.Message = rtl::OUString( "name clash during copy or move");
865 aAny <<= excep;
867 cancelCommandExecution(aAny,xEnv);
869 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
870 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
872 Reference<XInterface> xContext(
873 xComProc,UNO_QUERY);
874 UnsupportedNameClashException excep;
875 excep.NameClash = minorCode;
876 excep.Context = xContext;
877 excep.Message = rtl::OUString( "name clash value not supported during copy or move");
879 aAny <<= excep;
880 cancelCommandExecution(aAny,xEnv);
882 else
884 // case TASKHANDLER_NO_ERROR:
885 return;
890 } // end namespace fileaccess
892 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */