Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / file / filglob.cxx
blobef9e65f1b6d4267daceaac30fe994d3465f64479
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <stdio.h>
30 #include "filglob.hxx"
31 #include "filerror.hxx"
32 #include "shell.hxx"
33 #include "bc.hxx"
34 #include <osl/file.hxx>
35 #include <vector>
36 #include <ucbhelper/cancelcommandexecution.hxx>
37 #include <com/sun/star/ucb/CommandAbortedException.hpp>
38 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
39 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <com/sun/star/ucb/IOErrorCode.hpp>
42 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
43 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
44 #include <com/sun/star/ucb/NameClashException.hpp>
45 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
46 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
47 #include "com/sun/star/beans/PropertyState.hpp"
48 #include "com/sun/star/beans/PropertyValue.hpp"
49 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
50 #include "com/sun/star/uno/Any.hxx"
51 #include "com/sun/star/uno/Sequence.hxx"
52 #include "osl/diagnose.h"
53 #include "rtl/ustrbuf.hxx"
54 #include <rtl/uri.hxx>
55 #include <rtl/ustring.hxx>
56 #include "sal/types.h"
58 using namespace ucbhelper;
59 using namespace osl;
60 using namespace ::com::sun::star;
61 using namespace com::sun::star::task;
62 using namespace com::sun::star::beans;
63 using namespace com::sun::star::lang;
64 using namespace com::sun::star::uno;
65 using namespace com::sun::star::ucb;
67 namespace {
69 Sequence< Any > generateErrorArguments(
70 rtl::OUString const & rPhysicalUrl)
72 rtl::OUString aResourceName;
73 rtl::OUString aResourceType;
74 sal_Bool bRemovable;
75 bool bResourceName = false;
76 bool bResourceType = false;
77 bool bRemoveProperty = false;
79 if (osl::FileBase::getSystemPathFromFileURL(
80 rPhysicalUrl,
81 aResourceName)
82 == osl::FileBase::E_None)
83 bResourceName = true;
85 // The resource types "folder" (i.e., directory) and
86 // "volume" seem to be
87 // the most interesting when producing meaningful error messages:
88 osl::DirectoryItem aItem;
89 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
90 osl::FileBase::E_None)
92 osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
93 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
94 switch (aStatus.getFileType())
96 case osl::FileStatus::Directory:
97 aResourceType = rtl::OUString( "folder");
98 bResourceType = true;
99 break;
101 case osl::FileStatus::Volume:
103 aResourceType = rtl::OUString( "volume");
104 bResourceType = true;
105 osl::VolumeInfo aVolumeInfo(
106 osl_VolumeInfo_Mask_Attributes );
107 if( osl::Directory::getVolumeInfo(
108 rPhysicalUrl,aVolumeInfo ) ==
109 osl::FileBase::E_None )
111 bRemovable = aVolumeInfo.getRemoveableFlag();
112 bRemoveProperty = true;
115 break;
116 case osl::FileStatus::Regular:
117 case osl::FileStatus::Fifo:
118 case osl::FileStatus::Socket:
119 case osl::FileStatus::Link:
120 case osl::FileStatus::Special:
121 case osl::FileStatus::Unknown:
122 // do nothing for now
123 break;
127 Sequence< Any > aArguments( 1 +
128 (bResourceName ? 1 : 0) +
129 (bResourceType ? 1 : 0) +
130 (bRemoveProperty ? 1 : 0) );
131 sal_Int32 i = 0;
132 aArguments[i++]
133 <<= PropertyValue(rtl::OUString( "Uri"),
135 makeAny(rPhysicalUrl),
136 PropertyState_DIRECT_VALUE);
137 if (bResourceName)
138 aArguments[i++]
139 <<= PropertyValue(rtl::OUString( "ResourceName"),
141 makeAny(aResourceName),
142 PropertyState_DIRECT_VALUE);
143 if (bResourceType)
144 aArguments[i++]
145 <<= PropertyValue(rtl::OUString( "ResourceType"),
147 makeAny(aResourceType),
148 PropertyState_DIRECT_VALUE);
149 if (bRemoveProperty)
150 aArguments[i++]
151 <<= PropertyValue(rtl::OUString( "Removable"),
153 makeAny(bRemovable),
154 PropertyState_DIRECT_VALUE);
156 return aArguments;
162 namespace fileaccess {
165 sal_Bool isChild( const rtl::OUString& srcUnqPath,
166 const rtl::OUString& dstUnqPath )
168 static sal_Unicode slash = '/';
169 // Simple lexical comparison
170 sal_Int32 srcL = srcUnqPath.getLength();
171 sal_Int32 dstL = dstUnqPath.getLength();
173 return (
174 ( srcUnqPath == dstUnqPath )
176 ( ( dstL > srcL )
178 ( srcUnqPath.compareTo( dstUnqPath, srcL ) == 0 )
180 ( dstUnqPath[ srcL ] == slash ) )
185 rtl::OUString newName(
186 const rtl::OUString& aNewPrefix,
187 const rtl::OUString& aOldPrefix,
188 const rtl::OUString& old_Name )
190 sal_Int32 srcL = aOldPrefix.getLength();
192 rtl::OUString new_Name = old_Name.copy( srcL );
193 new_Name = ( aNewPrefix + new_Name );
194 return new_Name;
198 rtl::OUString getTitle( const rtl::OUString& aPath )
200 sal_Unicode slash = '/';
201 sal_Int32 lastIndex = aPath.lastIndexOf( slash );
202 return aPath.copy( lastIndex + 1 );
206 rtl::OUString getParentName( const rtl::OUString& aFileName )
208 sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') );
209 rtl::OUString aParent = aFileName.copy( 0,lastIndex );
211 if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 )
212 aParent += rtl::OUString("/");
214 if ( aParent == "file://" )
215 aParent = rtl::OUString("file:///");
217 return aParent;
221 osl::FileBase::RC osl_File_copy( const rtl::OUString& strPath,
222 const rtl::OUString& strDestPath,
223 sal_Bool test )
225 if( test )
227 osl::DirectoryItem aItem;
228 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
229 return osl::FileBase::E_EXIST;
232 return osl::File::copy( strPath,strDestPath );
236 osl::FileBase::RC osl_File_move( const rtl::OUString& strPath,
237 const rtl::OUString& strDestPath,
238 sal_Bool test )
240 if( test )
242 osl::DirectoryItem aItem;
243 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
244 return osl::FileBase::E_EXIST;
247 return osl::File::move( strPath,strDestPath );
250 void throw_handler(
251 sal_Int32 errorCode,
252 sal_Int32 minorCode,
253 const Reference< XCommandEnvironment >& xEnv,
254 const rtl::OUString& aUncPath,
255 BaseContent* pContent,
256 bool isHandled )
258 Reference<XCommandProcessor> xComProc(pContent);
259 Any aAny;
260 IOErrorCode ioErrorCode;
262 if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
264 aAny <<= UnsupportedCommandException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >() );
265 cancelCommandExecution( aAny,xEnv );
267 else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
268 errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
269 errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
270 errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
271 errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
272 errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT ||
273 errorCode == TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT )
275 IllegalArgumentException excep;
276 excep.ArgumentPosition = 0;
277 aAny <<= excep;
278 cancelCommandExecution(
279 aAny,xEnv);
281 else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
283 UnsupportedOpenModeException excep;
284 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
285 aAny <<= excep;
286 cancelCommandExecution( aAny,xEnv );
288 else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
289 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
290 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
292 // What to do here?
294 else if(
295 // error in opening file
296 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
297 // error in opening file
298 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
299 // error in opening file
300 errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
301 // error in opening file
302 errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
303 // error in opening file
304 errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
306 switch( minorCode )
308 case FileBase::E_NAMETOOLONG:
309 // pathname was too long
310 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
311 break;
312 case FileBase::E_NXIO:
313 // No such device or address
314 case FileBase::E_NODEV:
315 // No such device
316 ioErrorCode = IOErrorCode_INVALID_DEVICE;
317 break;
318 case FileBase::E_NOTDIR:
319 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
320 break;
321 case FileBase::E_NOENT:
322 // No such file or directory
323 ioErrorCode = IOErrorCode_NOT_EXISTING;
324 break;
325 case FileBase::E_ROFS:
326 // #i4735# handle ROFS transparently as ACCESS_DENIED
327 case FileBase::E_ACCES:
328 // permission denied<P>
329 ioErrorCode = IOErrorCode_ACCESS_DENIED;
330 break;
331 case FileBase::E_ISDIR:
332 // Is a directory<p>
333 ioErrorCode = IOErrorCode_NO_FILE;
334 break;
335 case FileBase::E_NOTREADY:
336 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
337 break;
338 case FileBase::E_MFILE:
339 // too many open files used by the process
340 case FileBase::E_NFILE:
341 // too many open files in the system
342 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
343 break;
344 case FileBase::E_INVAL:
345 // the format of the parameters was not valid
346 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
347 break;
348 case FileBase::E_NOMEM:
349 // not enough memory for allocating structures
350 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
351 break;
352 case FileBase::E_BUSY:
353 // Text file busy
354 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
355 break;
356 case FileBase::E_AGAIN:
357 // Operation would block
358 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
359 break;
360 case FileBase::E_NOLCK: // No record locks available
361 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
362 break;
364 case FileBase::E_FAULT: // Bad address
365 case FileBase::E_LOOP: // Too many symbolic links encountered
366 case FileBase::E_NOSPC: // No space left on device
367 case FileBase::E_INTR: // function call was interrupted
368 case FileBase::E_IO: // I/O error
369 case FileBase::E_MULTIHOP: // Multihop attempted
370 case FileBase::E_NOLINK: // Link has been severed
371 default:
372 ioErrorCode = IOErrorCode_GENERAL;
373 break;
376 cancelCommandExecution(
377 ioErrorCode,
378 generateErrorArguments(aUncPath),
379 xEnv,
380 rtl::OUString( "an error occurred during file opening"),
381 xComProc);
383 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
384 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
386 switch( minorCode )
388 case FileBase::E_INVAL:
389 // the format of the parameters was not valid
390 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
391 break;
392 case FileBase::E_NOENT:
393 // the specified path doesn't exist
394 ioErrorCode = IOErrorCode_NOT_EXISTING;
395 break;
396 case FileBase::E_NOTDIR:
397 // the specified path is not an directory
398 ioErrorCode = IOErrorCode_NO_DIRECTORY;
399 break;
400 case FileBase::E_NOMEM:
401 // not enough memory for allocating structures
402 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
403 break;
404 case FileBase::E_ROFS:
405 // #i4735# handle ROFS transparently as ACCESS_DENIED
406 case FileBase::E_ACCES: // permission denied
407 ioErrorCode = IOErrorCode_ACCESS_DENIED;
408 break;
409 case FileBase::E_NOTREADY:
410 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
411 break;
412 case FileBase::E_MFILE:
413 // too many open files used by the process
414 case FileBase::E_NFILE:
415 // too many open files in the system
416 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
417 break;
418 case FileBase::E_NAMETOOLONG:
419 // File name too long
420 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
421 break;
422 case FileBase::E_LOOP:
423 // Too many symbolic links encountered<p>
424 default:
425 ioErrorCode = IOErrorCode_GENERAL;
426 break;
429 cancelCommandExecution(
430 ioErrorCode,
431 generateErrorArguments(aUncPath),
432 xEnv,
433 rtl::OUString( "an error occurred during opening a directory"),
434 xComProc);
436 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
437 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
438 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
439 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
440 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
441 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
443 ioErrorCode = IOErrorCode_UNKNOWN;
444 cancelCommandExecution(
445 ioErrorCode,
446 generateErrorArguments(aUncPath),
447 xEnv,
448 rtl::OUString( "an error occurred writing or reading from a file"),
449 xComProc );
451 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
453 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
454 cancelCommandExecution(
455 ioErrorCode,
456 generateErrorArguments(aUncPath),
457 xEnv,
458 rtl::OUString( "device full"),
459 xComProc);
461 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
462 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
464 switch( minorCode )
466 case FileBase::E_INVAL:
467 // the format of the parameters was not valid
468 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
469 break;
470 case FileBase::E_FBIG:
471 // File too large
472 ioErrorCode = IOErrorCode_CANT_WRITE;
473 break;
474 case FileBase::E_NOSPC:
475 // No space left on device
476 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
477 break;
478 case FileBase::E_NXIO:
479 // No such device or address
480 ioErrorCode = IOErrorCode_INVALID_DEVICE;
481 break;
482 case FileBase::E_NOLINK:
483 // Link has been severed
484 case FileBase::E_ISDIR:
485 // Is a directory
486 ioErrorCode = IOErrorCode_NO_FILE;
487 break;
488 case FileBase::E_AGAIN:
489 // Operation would block
490 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
491 break;
492 case FileBase::E_TIMEDOUT:
493 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
494 break;
495 case FileBase::E_NOLCK: // No record locks available
496 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
497 break;
498 case FileBase::E_IO: // I/O error
499 case FileBase::E_BADF: // Bad file
500 case FileBase::E_FAULT: // Bad address
501 case FileBase::E_INTR: // function call was interrupted
502 default:
503 ioErrorCode = IOErrorCode_GENERAL;
504 break;
506 cancelCommandExecution(
507 ioErrorCode,
508 generateErrorArguments(aUncPath),
509 xEnv,
510 rtl::OUString( "an error occurred during opening a file"),
511 xComProc);
513 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
514 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
516 Sequence< ::rtl::OUString > aSeq( 1 );
517 aSeq[0] =
518 ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
519 rtl::OUString("Title") :
520 rtl::OUString("ContentType");
522 aAny <<= MissingPropertiesException(
523 rtl::OUString( "a property is missing necessary"
524 "to create a content"),
525 xComProc,
526 aSeq);
527 cancelCommandExecution(aAny,xEnv);
529 else if( errorCode == TASKHANDLING_FILESIZE_FOR_WRITE )
531 switch( minorCode )
533 case FileBase::E_INVAL:
534 // the format of the parameters was not valid
535 case FileBase::E_OVERFLOW:
536 // The resulting file offset would be a value which cannot
537 // be represented correctly for regular files
538 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
539 break;
540 default:
541 ioErrorCode = IOErrorCode_GENERAL;
542 break;
544 cancelCommandExecution(
545 ioErrorCode,
546 generateErrorArguments(aUncPath),
547 xEnv,
548 rtl::OUString( "there were problems with the filesize"),
549 xComProc);
551 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
553 Reference<XInterface> xContext(xComProc,UNO_QUERY);
554 aAny <<=
555 MissingInputStreamException(
556 rtl::OUString( "the inputstream is missing necessary"
557 "to create a content"),
558 xContext);
559 cancelCommandExecution(aAny,xEnv);
561 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
562 // Overwrite = false and file exists
564 NameClashException excep;
565 excep.Name = getTitle(aUncPath);
566 excep.Classification = InteractionClassification_ERROR;
567 Reference<XInterface> xContext(xComProc,UNO_QUERY);
568 excep.Context = xContext;
569 excep.Message = rtl::OUString( "file exists and overwrite forbidden");
570 aAny <<= excep;
571 cancelCommandExecution( aAny,xEnv );
573 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
575 InteractiveAugmentedIOException excep;
576 excep.Code = IOErrorCode_INVALID_CHARACTER;
577 PropertyValue prop;
578 prop.Name = rtl::OUString("ResourceName");
579 prop.Handle = -1;
580 rtl::OUString m_aClashingName(
581 rtl::Uri::decode(
582 getTitle(aUncPath),
583 rtl_UriDecodeWithCharset,
584 RTL_TEXTENCODING_UTF8));
585 prop.Value <<= m_aClashingName;
586 Sequence<Any> seq(1);
587 seq[0] <<= prop;
588 excep.Arguments = seq;
589 excep.Classification = InteractionClassification_ERROR;
590 Reference<XInterface> xContext(xComProc,UNO_QUERY);
591 excep.Context = xContext;
592 excep.Message = rtl::OUString( "the name contained invalid characters");
593 if(isHandled)
594 throw excep;
595 else {
596 aAny <<= excep;
597 cancelCommandExecution( aAny,xEnv );
599 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
600 // cancelCommandExecution(
601 // ioErrorCode,
602 // generateErrorArguments(aUncPath),
603 // xEnv,
604 // rtl::OUString( "the name contained invalid characters"),
605 // xComProc );
607 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
609 NameClashException excep;
610 excep.Name = getTitle(aUncPath);
611 excep.Classification = InteractionClassification_ERROR;
612 Reference<XInterface> xContext(xComProc,UNO_QUERY);
613 excep.Context = xContext;
614 excep.Message = rtl::OUString( "folder exists and overwrite forbidden");
615 if(isHandled)
616 throw excep;
617 else {
618 aAny <<= excep;
619 cancelCommandExecution( aAny,xEnv );
621 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
622 // cancelCommandExecution(
623 // ioErrorCode,
624 // generateErrorArguments(aUncPath),
625 // xEnv,
626 // rtl::OUString( "the folder exists"),
627 // xComProc );
629 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
630 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
632 switch( minorCode )
634 case FileBase::E_ACCES:
635 ioErrorCode = IOErrorCode_ACCESS_DENIED;
636 break;
637 case FileBase::E_ROFS:
638 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
639 break;
640 case FileBase::E_NAMETOOLONG:
641 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
642 break;
643 default:
644 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
645 break;
647 cancelCommandExecution(
648 ioErrorCode,
649 generateErrorArguments(getParentName(aUncPath)),
650 //TODO! ok to supply physical URL to getParentName()?
651 xEnv,
652 rtl::OUString( "a folder could not be created"),
653 xComProc );
655 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
656 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
657 errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
659 switch( minorCode )
661 case FileBase::E_INVAL: // the format of the parameters was not valid
662 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
663 break;
664 case FileBase::E_NOMEM: // not enough memory for allocating structures
665 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
666 break;
667 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
668 case FileBase::E_ACCES: // permission denied
669 ioErrorCode = IOErrorCode_ACCESS_DENIED;
670 break;
671 case FileBase::E_MFILE: // too many open files used by the process
672 case FileBase::E_NFILE: // too many open files in the system
673 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
674 break;
675 case FileBase::E_NOLINK: // Link has been severed
676 case FileBase::E_NOENT: // No such file or directory
677 ioErrorCode = IOErrorCode_NOT_EXISTING;
678 break;
679 case FileBase::E_NAMETOOLONG: // File name too long
680 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
681 break;
682 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
683 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
684 break;
685 case FileBase::E_LOOP: // Too many symbolic links encountered
686 case FileBase::E_IO: // I/O error
687 case FileBase::E_MULTIHOP: // Multihop attempted
688 case FileBase::E_FAULT: // Bad address
689 case FileBase::E_INTR: // function call was interrupted
690 case FileBase::E_NOSYS: // Function not implemented
691 case FileBase::E_NOSPC: // No space left on device
692 case FileBase::E_NXIO: // No such device or address
693 case FileBase::E_OVERFLOW: // Value too large for defined data type
694 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
695 default:
696 ioErrorCode = IOErrorCode_GENERAL;
697 break;
699 cancelCommandExecution(
700 ioErrorCode,
701 generateErrorArguments(aUncPath),
702 xEnv,
703 rtl::OUString( "a file status object could not be filled"),
704 xComProc );
706 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
707 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
709 switch( minorCode )
711 case FileBase::E_INVAL: // the format of the parameters was not valid
712 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
713 break;
714 case FileBase::E_NOMEM: // not enough memory for allocating structures
715 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
716 break;
717 case FileBase::E_ACCES: // Permission denied
718 ioErrorCode = IOErrorCode_ACCESS_DENIED;
719 break;
720 case FileBase::E_PERM: // Operation not permitted
721 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
722 break;
723 case FileBase::E_NAMETOOLONG: // File name too long
724 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
725 break;
726 case FileBase::E_NOLINK: // Link has been severed
727 case FileBase::E_NOENT: // No such file or directory
728 ioErrorCode = IOErrorCode_NOT_EXISTING;
729 break;
730 case FileBase::E_ISDIR: // Is a directory
731 case FileBase::E_ROFS: // Read-only file system
732 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
733 break;
734 case FileBase::E_BUSY: // Device or resource busy
735 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
736 break;
737 case FileBase::E_FAULT: // Bad address
738 case FileBase::E_LOOP: // Too many symbolic links encountered
739 case FileBase::E_IO: // I/O error
740 case FileBase::E_INTR: // function call was interrupted
741 case FileBase::E_MULTIHOP: // Multihop attempted
742 default:
743 ioErrorCode = IOErrorCode_GENERAL;
744 break;
746 cancelCommandExecution(
747 ioErrorCode,
748 generateErrorArguments(aUncPath),
749 xEnv,
750 rtl::OUString( "a file or directory could not be deleted"),
751 xComProc );
753 else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
754 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
755 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
756 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
757 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
758 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
759 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
760 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
762 rtl::OUString aMsg;
763 switch( minorCode )
765 case FileBase::E_NOENT: // No such file or directory
766 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
767 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
768 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
769 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
771 ioErrorCode = IOErrorCode_NOT_EXISTING;
772 aMsg = rtl::OUString( "source file/folder does not exist");
773 break;
775 else
777 ioErrorCode = IOErrorCode_GENERAL;
778 aMsg = rtl::OUString( "a general error during transfer command");
779 break;
781 default:
782 ioErrorCode = IOErrorCode_GENERAL;
783 aMsg = rtl::OUString( "a general error during transfer command");
784 break;
786 cancelCommandExecution(
787 ioErrorCode,
788 generateErrorArguments(aUncPath),
789 xEnv,
790 aMsg,
791 xComProc );
793 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
795 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
796 cancelCommandExecution(
797 ioErrorCode,
798 generateErrorArguments(aUncPath),
799 xEnv,
800 rtl::OUString( "accessing the root during transfer"),
801 xComProc );
803 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
805 Reference<XInterface> xContext(xComProc,UNO_QUERY);
807 aAny <<=
808 InteractiveBadTransferURLException(
809 rtl::OUString( "bad tranfer url"),
810 xContext);
811 cancelCommandExecution( aAny,xEnv );
813 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
814 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
815 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
816 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
817 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
818 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
819 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
820 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
821 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
822 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
824 rtl::OUString aMsg(
825 "general error during transfer");
827 switch( minorCode )
829 case FileBase::E_EXIST:
830 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
831 break;
832 case FileBase::E_INVAL: // the format of the parameters was not valid
833 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
834 break;
835 case FileBase::E_NOMEM: // not enough memory for allocating structures
836 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
837 break;
838 case FileBase::E_ACCES: // Permission denied
839 ioErrorCode = IOErrorCode_ACCESS_DENIED;
840 break;
841 case FileBase::E_PERM: // Operation not permitted
842 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
843 break;
844 case FileBase::E_NAMETOOLONG: // File name too long
845 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
846 break;
847 case FileBase::E_NOENT: // No such file or directory
848 ioErrorCode = IOErrorCode_NOT_EXISTING;
849 aMsg = rtl::OUString( "file/folder does not exist");
850 break;
851 case FileBase::E_ROFS: // Read-only file system<p>
852 ioErrorCode = IOErrorCode_NOT_EXISTING;
853 break;
854 default:
855 ioErrorCode = IOErrorCode_GENERAL;
856 break;
858 cancelCommandExecution(
859 ioErrorCode,
860 generateErrorArguments(aUncPath),
861 xEnv,
862 aMsg,
863 xComProc );
865 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
866 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
868 NameClashException excep;
869 excep.Name = getTitle(aUncPath);
870 excep.Classification = InteractionClassification_ERROR;
871 Reference<XInterface> xContext(xComProc,UNO_QUERY);
872 excep.Context = xContext;
873 excep.Message = rtl::OUString( "name clash during copy or move");
874 aAny <<= excep;
876 cancelCommandExecution(aAny,xEnv);
878 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
879 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
881 Reference<XInterface> xContext(
882 xComProc,UNO_QUERY);
883 UnsupportedNameClashException excep;
884 excep.NameClash = minorCode;
885 excep.Context = xContext;
886 excep.Message = rtl::OUString( "name clash value not supported during copy or move");
888 aAny <<= excep;
889 cancelCommandExecution(aAny,xEnv);
891 else
893 // case TASKHANDLER_NO_ERROR:
894 return;
899 } // end namespace fileaccess
901 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */