update dev300-m58
[ooovba.git] / ucb / source / ucp / file / filglob.cxx
blobd50f04c85810ca5d9e921ffc12f795efb5a47af9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filglob.cxx,v $
10 * $Revision: 1.26.4.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include <stdio.h>
34 #include "filglob.hxx"
35 #ifndef _FILERROR_HXX_
36 #include "filerror.hxx"
37 #endif
38 #include "shell.hxx"
39 #include "bc.hxx"
40 #include <osl/file.hxx>
41 #ifndef INCLUDED_STL_VECTOR
42 #include <vector>
43 #define INCLUDED_STL_VECTOR
44 #endif
45 #include <ucbhelper/cancelcommandexecution.hxx>
46 #include <com/sun/star/ucb/CommandAbortedException.hpp>
47 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
48 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
49 #include <com/sun/star/lang/IllegalArgumentException.hpp>
50 #include <com/sun/star/ucb/IOErrorCode.hpp>
51 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
52 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
53 #include <com/sun/star/ucb/NameClashException.hpp>
54 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
55 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
56 #include "com/sun/star/beans/PropertyState.hpp"
57 #include "com/sun/star/beans/PropertyValue.hpp"
58 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
59 #include "com/sun/star/uno/Any.hxx"
60 #include "com/sun/star/uno/Sequence.hxx"
61 #include "osl/diagnose.h"
62 #include "rtl/ustrbuf.hxx"
63 #include <rtl/uri.hxx>
64 #include <rtl/ustring.hxx>
65 #include "sal/types.h"
67 using namespace ucbhelper;
68 using namespace osl;
69 using namespace ::com::sun::star;
70 using namespace com::sun::star::task;
71 using namespace com::sun::star::beans;
72 using namespace com::sun::star::lang;
73 using namespace com::sun::star::uno;
74 using namespace com::sun::star::ucb;
76 namespace {
78 Sequence< Any > generateErrorArguments(
79 rtl::OUString const & rPhysicalUrl)
81 rtl::OUString aResourceName;
82 rtl::OUString aResourceType;
83 sal_Bool bRemovable;
84 bool bResourceName = false;
85 bool bResourceType = false;
86 bool bRemoveProperty = false;
88 if (osl::FileBase::getSystemPathFromFileURL(
89 rPhysicalUrl,
90 aResourceName)
91 == osl::FileBase::E_None)
92 bResourceName = true;
94 // The resource types "folder" (i.e., directory) and
95 // "volume" seem to be
96 // the most interesting when producing meaningful error messages:
97 osl::DirectoryItem aItem;
98 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
99 osl::FileBase::E_None)
101 osl::FileStatus aStatus( FileStatusMask_Type );
102 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
103 switch (aStatus.getFileType())
105 case osl::FileStatus::Directory:
106 aResourceType
107 = rtl::OUString(
108 RTL_CONSTASCII_USTRINGPARAM("folder"));
109 bResourceType = true;
110 break;
112 case osl::FileStatus::Volume:
114 aResourceType
115 = rtl::OUString(
116 RTL_CONSTASCII_USTRINGPARAM("volume"));
117 bResourceType = true;
118 osl::VolumeInfo aVolumeInfo(
119 VolumeInfoMask_Attributes );
120 if( osl::Directory::getVolumeInfo(
121 rPhysicalUrl,aVolumeInfo ) ==
122 osl::FileBase::E_None )
124 bRemovable = aVolumeInfo.getRemoveableFlag();
125 bRemoveProperty = true;
128 break;
129 case osl::FileStatus::Regular:
130 case osl::FileStatus::Fifo:
131 case osl::FileStatus::Socket:
132 case osl::FileStatus::Link:
133 case osl::FileStatus::Special:
134 case osl::FileStatus::Unknown:
135 // do nothing for now
136 break;
140 Sequence< Any > aArguments( 1 +
141 (bResourceName ? 1 : 0) +
142 (bResourceType ? 1 : 0) +
143 (bRemoveProperty ? 1 : 0) );
144 sal_Int32 i = 0;
145 aArguments[i++]
146 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
147 "Uri")),
149 makeAny(rPhysicalUrl),
150 PropertyState_DIRECT_VALUE);
151 if (bResourceName)
152 aArguments[i++]
153 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
154 "ResourceName")),
156 makeAny(aResourceName),
157 PropertyState_DIRECT_VALUE);
158 if (bResourceType)
159 aArguments[i++]
160 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
161 "ResourceType")),
163 makeAny(aResourceType),
164 PropertyState_DIRECT_VALUE);
165 if (bRemoveProperty)
166 aArguments[i++]
167 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
168 "Removable")),
170 makeAny(bRemovable),
171 PropertyState_DIRECT_VALUE);
173 return aArguments;
179 namespace fileaccess {
182 sal_Bool isChild( const rtl::OUString& srcUnqPath,
183 const rtl::OUString& dstUnqPath )
185 static sal_Unicode slash = '/';
186 // Simple lexical comparison
187 sal_Int32 srcL = srcUnqPath.getLength();
188 sal_Int32 dstL = dstUnqPath.getLength();
190 return (
191 ( srcUnqPath == dstUnqPath )
193 ( ( dstL > srcL )
195 ( srcUnqPath.compareTo( dstUnqPath, srcL ) == 0 )
197 ( dstUnqPath[ srcL ] == slash ) )
202 rtl::OUString newName(
203 const rtl::OUString& aNewPrefix,
204 const rtl::OUString& aOldPrefix,
205 const rtl::OUString& old_Name )
207 sal_Int32 srcL = aOldPrefix.getLength();
209 rtl::OUString new_Name = old_Name.copy( srcL );
210 new_Name = ( aNewPrefix + new_Name );
211 return new_Name;
215 rtl::OUString getTitle( const rtl::OUString& aPath )
217 sal_Unicode slash = '/';
218 sal_Int32 lastIndex = aPath.lastIndexOf( slash );
219 return aPath.copy( lastIndex + 1 );
223 rtl::OUString getParentName( const rtl::OUString& aFileName )
225 sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') );
226 rtl::OUString aParent = aFileName.copy( 0,lastIndex );
228 if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 )
229 aParent += rtl::OUString::createFromAscii( "/" );
231 if( 0 == aParent.compareToAscii( "file://" ) )
232 aParent = rtl::OUString::createFromAscii( "file:///" );
234 return aParent;
238 osl::FileBase::RC osl_File_copy( const rtl::OUString& strPath,
239 const rtl::OUString& strDestPath,
240 sal_Bool test )
242 if( test )
244 osl::DirectoryItem aItem;
245 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
246 return osl::FileBase::E_EXIST;
249 return osl::File::copy( strPath,strDestPath );
253 osl::FileBase::RC osl_File_move( const rtl::OUString& strPath,
254 const rtl::OUString& strDestPath,
255 sal_Bool test )
257 if( test )
259 osl::DirectoryItem aItem;
260 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
261 return osl::FileBase::E_EXIST;
264 return osl::File::move( strPath,strDestPath );
267 void throw_handler(
268 sal_Int32 errorCode,
269 sal_Int32 minorCode,
270 const Reference< XCommandEnvironment >& xEnv,
271 const rtl::OUString& aUncPath,
272 BaseContent* pContent,
273 bool isHandled )
275 Reference<XCommandProcessor> xComProc(pContent);
276 Any aAny;
277 IOErrorCode ioErrorCode;
279 if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
281 aAny <<= UnsupportedCommandException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
282 cancelCommandExecution( aAny,xEnv );
284 else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
285 errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
286 errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
287 errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
288 errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
289 errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT )
291 IllegalArgumentException excep;
292 excep.ArgumentPosition = 0;
293 aAny <<= excep;
294 cancelCommandExecution(
295 aAny,xEnv);
297 else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
299 UnsupportedOpenModeException excep;
300 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
301 aAny <<= excep;
302 cancelCommandExecution( aAny,xEnv );
304 else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
305 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
306 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
308 // What to do here?
310 else if(
311 // error in opening file
312 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
313 // error in opening file
314 errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
315 // error in opening file
316 errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
317 // error in opening file
318 errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
319 // error in opening file
320 errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
322 switch( minorCode )
324 case FileBase::E_NAMETOOLONG:
325 // pathname was too long
326 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
327 break;
328 case FileBase::E_NXIO:
329 // No such device or address
330 case FileBase::E_NODEV:
331 // No such device
332 ioErrorCode = IOErrorCode_INVALID_DEVICE;
333 break;
334 case FileBase::E_NOENT:
335 // No such file or directory
336 ioErrorCode = IOErrorCode_NOT_EXISTING;
337 break;
338 case FileBase::E_ROFS:
339 // #i4735# handle ROFS transparently as ACCESS_DENIED
340 case FileBase::E_ACCES:
341 // permission denied<P>
342 ioErrorCode = IOErrorCode_ACCESS_DENIED;
343 break;
344 case FileBase::E_ISDIR:
345 // Is a directory<p>
346 ioErrorCode = IOErrorCode_NO_FILE;
347 break;
348 case FileBase::E_NOTREADY:
349 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
350 break;
351 case FileBase::E_MFILE:
352 // too many open files used by the process
353 case FileBase::E_NFILE:
354 // too many open files in the system
355 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
356 break;
357 case FileBase::E_INVAL:
358 // the format of the parameters was not valid
359 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
360 break;
361 case FileBase::E_NOMEM:
362 // not enough memory for allocating structures
363 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
364 break;
366 case FileBase::E_BUSY: // Text file busy
367 case FileBase::E_AGAIN: // Operation would block
368 case FileBase::E_NOLCK: // No record locks available
369 case FileBase::E_TXTBSY:// Text file busy
370 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
371 break;
373 case FileBase::E_FAULT: // Bad address
374 case FileBase::E_LOOP: // Too many symbolic links encountered
375 case FileBase::E_NOSPC: // No space left on device
376 case FileBase::E_INTR: // function call was interrupted
377 case FileBase::E_IO: // I/O error
378 case FileBase::E_MULTIHOP: // Multihop attempted
379 case FileBase::E_NOLINK: // Link has been severed
380 default:
381 ioErrorCode = IOErrorCode_GENERAL;
382 break;
385 cancelCommandExecution(
386 ioErrorCode,
387 generateErrorArguments(aUncPath),
388 xEnv,
389 rtl::OUString(
390 RTL_CONSTASCII_USTRINGPARAM(
391 "an error occured during file opening")),
392 xComProc);
394 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
395 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
397 switch( minorCode )
399 case FileBase::E_INVAL:
400 // the format of the parameters was not valid
401 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
402 break;
403 case FileBase::E_NOENT:
404 // the specified path doesn't exist
405 ioErrorCode = IOErrorCode_NOT_EXISTING;
406 break;
407 case FileBase::E_NOTDIR:
408 // the specified path is not an directory
409 ioErrorCode = IOErrorCode_NO_DIRECTORY;
410 break;
411 case FileBase::E_NOMEM:
412 // not enough memory for allocating structures
413 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
414 break;
415 case FileBase::E_ROFS:
416 // #i4735# handle ROFS transparently as ACCESS_DENIED
417 case FileBase::E_ACCES: // permission denied
418 ioErrorCode = IOErrorCode_ACCESS_DENIED;
419 break;
420 case FileBase::E_NOTREADY:
421 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
422 break;
423 case FileBase::E_MFILE:
424 // too many open files used by the process
425 case FileBase::E_NFILE:
426 // too many open files in the system
427 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
428 break;
429 case FileBase::E_NAMETOOLONG:
430 // File name too long
431 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
432 break;
433 case FileBase::E_LOOP:
434 // Too many symbolic links encountered<p>
435 default:
436 ioErrorCode = IOErrorCode_GENERAL;
437 break;
440 cancelCommandExecution(
441 ioErrorCode,
442 generateErrorArguments(aUncPath),
443 xEnv,
444 rtl::OUString(
445 RTL_CONSTASCII_USTRINGPARAM(
446 "an error occured during opening a directory")),
447 xComProc);
449 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
450 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
451 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
452 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
453 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
454 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
456 ioErrorCode = IOErrorCode_UNKNOWN;
457 cancelCommandExecution(
458 ioErrorCode,
459 generateErrorArguments(aUncPath),
460 xEnv,
461 rtl::OUString(
462 RTL_CONSTASCII_USTRINGPARAM(
463 "an error occured writing or reading from a file")),
464 xComProc );
466 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
468 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
469 cancelCommandExecution(
470 ioErrorCode,
471 generateErrorArguments(aUncPath),
472 xEnv,
473 rtl::OUString(
474 RTL_CONSTASCII_USTRINGPARAM(
475 "device full")),
476 xComProc);
478 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
479 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
481 switch( minorCode )
483 case FileBase::E_INVAL:
484 // the format of the parameters was not valid
485 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
486 break;
487 case FileBase::E_FBIG:
488 // File too large
489 ioErrorCode = IOErrorCode_CANT_WRITE;
490 break;
491 case FileBase::E_NOSPC:
492 // No space left on device
493 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
494 break;
495 case FileBase::E_NXIO:
496 // No such device or address
497 ioErrorCode = IOErrorCode_INVALID_DEVICE;
498 break;
499 case FileBase::E_NOLINK:
500 // Link has been severed
501 case FileBase::E_ISDIR:
502 // Is a directory
503 ioErrorCode = IOErrorCode_NO_FILE;
504 break;
505 case FileBase::E_AGAIN:
506 // Operation would block
507 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
508 break;
509 case FileBase::E_TIMEDOUT:
510 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
511 break;
512 case FileBase::E_NOLCK: // No record locks available
513 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
514 break;
515 case FileBase::E_IO: // I/O error
516 case FileBase::E_BADF: // Bad file
517 case FileBase::E_FAULT: // Bad address
518 case FileBase::E_INTR: // function call was interrupted
519 default:
520 ioErrorCode = IOErrorCode_GENERAL;
521 break;
523 cancelCommandExecution(
524 ioErrorCode,
525 generateErrorArguments(aUncPath),
526 xEnv,
527 rtl::OUString(
528 RTL_CONSTASCII_USTRINGPARAM(
529 "an error occured during opening a file")),
530 xComProc);
532 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
533 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
535 Sequence< ::rtl::OUString > aSeq( 1 );
536 aSeq[0] =
537 ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
538 rtl::OUString::createFromAscii( "Title" ) :
539 rtl::OUString::createFromAscii( "ContentType" );
541 aAny <<= MissingPropertiesException(
542 rtl::OUString(
543 RTL_CONSTASCII_USTRINGPARAM(
544 "a property is missing necessary"
545 "to create a content")),
546 xComProc,
547 aSeq);
548 cancelCommandExecution(aAny,xEnv);
550 else if( errorCode == TASKHANDLING_FILESIZE_FOR_WRITE )
552 switch( minorCode )
554 case FileBase::E_INVAL:
555 // the format of the parameters was not valid
556 case FileBase::E_OVERFLOW:
557 // The resulting file offset would be a value which cannot
558 // be represented correctly for regular files
559 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
560 break;
561 default:
562 ioErrorCode = IOErrorCode_GENERAL;
563 break;
565 cancelCommandExecution(
566 ioErrorCode,
567 generateErrorArguments(aUncPath),
568 xEnv,
569 rtl::OUString(
570 RTL_CONSTASCII_USTRINGPARAM(
571 "there were problems with the filesize")),
572 xComProc);
574 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
576 Reference<XInterface> xContext(xComProc,UNO_QUERY);
577 aAny <<=
578 MissingInputStreamException(
579 rtl::OUString(
580 RTL_CONSTASCII_USTRINGPARAM(
581 "the inputstream is missing necessary"
582 "to create a content")),
583 xContext);
584 cancelCommandExecution(aAny,xEnv);
586 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
587 // Overwrite = false and file exists
589 NameClashException excep;
590 excep.Name = getTitle(aUncPath);
591 excep.Classification = InteractionClassification_ERROR;
592 Reference<XInterface> xContext(xComProc,UNO_QUERY);
593 excep.Context = xContext;
594 excep.Message = rtl::OUString(
595 RTL_CONSTASCII_USTRINGPARAM(
596 "file exists and overwrite forbidden"));
597 aAny <<= excep;
598 cancelCommandExecution( aAny,xEnv );
600 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
602 InteractiveAugmentedIOException excep;
603 excep.Code = IOErrorCode_INVALID_CHARACTER;
604 PropertyValue prop;
605 prop.Name = rtl::OUString::createFromAscii("ResourceName");
606 prop.Handle = -1;
607 rtl::OUString m_aClashingName(
608 rtl::Uri::decode(
609 getTitle(aUncPath),
610 rtl_UriDecodeWithCharset,
611 RTL_TEXTENCODING_UTF8));
612 prop.Value <<= m_aClashingName;
613 Sequence<Any> seq(1);
614 seq[0] <<= prop;
615 excep.Arguments = seq;
616 excep.Classification = InteractionClassification_ERROR;
617 Reference<XInterface> xContext(xComProc,UNO_QUERY);
618 excep.Context = xContext;
619 excep.Message = rtl::OUString(
620 RTL_CONSTASCII_USTRINGPARAM(
621 "the name contained invalid characters"));
622 if(isHandled)
623 throw excep;
624 else {
625 aAny <<= excep;
626 cancelCommandExecution( aAny,xEnv );
628 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
629 // cancelCommandExecution(
630 // ioErrorCode,
631 // generateErrorArguments(aUncPath),
632 // xEnv,
633 // rtl::OUString(
634 // RTL_CONSTASCII_USTRINGPARAM(
635 // "the name contained invalid characters")),
636 // xComProc );
638 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
640 NameClashException excep;
641 excep.Name = getTitle(aUncPath);
642 excep.Classification = InteractionClassification_ERROR;
643 Reference<XInterface> xContext(xComProc,UNO_QUERY);
644 excep.Context = xContext;
645 excep.Message = rtl::OUString(
646 RTL_CONSTASCII_USTRINGPARAM(
647 "folder exists and overwrite forbidden"));
648 if(isHandled)
649 throw excep;
650 else {
651 aAny <<= excep;
652 cancelCommandExecution( aAny,xEnv );
654 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
655 // cancelCommandExecution(
656 // ioErrorCode,
657 // generateErrorArguments(aUncPath),
658 // xEnv,
659 // rtl::OUString(
660 // RTL_CONSTASCII_USTRINGPARAM(
661 // "the folder exists")),
662 // xComProc );
664 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
665 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
667 switch( minorCode )
669 case FileBase::E_ACCES:
670 ioErrorCode = IOErrorCode_ACCESS_DENIED;
671 break;
672 case FileBase::E_ROFS:
673 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
674 break;
675 case FileBase::E_NAMETOOLONG:
676 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
677 break;
678 default:
679 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
680 break;
682 cancelCommandExecution(
683 ioErrorCode,
684 generateErrorArguments(getParentName(aUncPath)),
685 //TODO! ok to supply physical URL to getParentName()?
686 xEnv,
687 rtl::OUString(
688 RTL_CONSTASCII_USTRINGPARAM(
689 "a folder could not be created")),
690 xComProc );
692 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
693 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
694 errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
696 switch( minorCode )
698 case FileBase::E_INVAL: // the format of the parameters was not valid
699 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
700 break;
701 case FileBase::E_NOMEM: // not enough memory for allocating structures
702 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
703 break;
704 case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
705 case FileBase::E_ACCES: // permission denied
706 ioErrorCode = IOErrorCode_ACCESS_DENIED;
707 break;
708 case FileBase::E_MFILE: // too many open files used by the process
709 case FileBase::E_NFILE: // too many open files in the system
710 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
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_NAMETOOLONG: // File name too long
717 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
718 break;
719 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
720 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
721 break;
722 case FileBase::E_LOOP: // Too many symbolic links encountered
723 case FileBase::E_IO: // I/O error
724 case FileBase::E_MULTIHOP: // Multihop attempted
725 case FileBase::E_FAULT: // Bad address
726 case FileBase::E_INTR: // function call was interrupted
727 case FileBase::E_NOSYS: // Function not implemented
728 case FileBase::E_NOSPC: // No space left on device
729 case FileBase::E_NXIO: // No such device or address
730 case FileBase::E_OVERFLOW: // Value too large for defined data type
731 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
732 default:
733 ioErrorCode = IOErrorCode_GENERAL;
734 break;
736 cancelCommandExecution(
737 ioErrorCode,
738 generateErrorArguments(aUncPath),
739 xEnv,
740 rtl::OUString(
741 RTL_CONSTASCII_USTRINGPARAM(
742 "a file status object could not be filled")),
743 xComProc );
745 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
746 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
748 switch( minorCode )
750 case FileBase::E_INVAL: // the format of the parameters was not valid
751 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
752 break;
753 case FileBase::E_NOMEM: // not enough memory for allocating structures
754 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
755 break;
756 case FileBase::E_ACCES: // Permission denied
757 ioErrorCode = IOErrorCode_ACCESS_DENIED;
758 break;
759 case FileBase::E_PERM: // Operation not permitted
760 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
761 break;
762 case FileBase::E_NAMETOOLONG: // File name too long
763 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
764 break;
765 case FileBase::E_NOLINK: // Link has been severed
766 case FileBase::E_NOENT: // No such file or directory
767 ioErrorCode = IOErrorCode_NOT_EXISTING;
768 break;
769 case FileBase::E_ISDIR: // Is a directory
770 case FileBase::E_ROFS: // Read-only file system
771 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
772 break;
773 case FileBase::E_BUSY: // Device or resource busy
774 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
775 break;
776 case FileBase::E_FAULT: // Bad address
777 case FileBase::E_LOOP: // Too many symbolic links encountered
778 case FileBase::E_IO: // I/O error
779 case FileBase::E_INTR: // function call was interrupted
780 case FileBase::E_MULTIHOP: // Multihop attempted
781 default:
782 ioErrorCode = IOErrorCode_GENERAL;
783 break;
785 cancelCommandExecution(
786 ioErrorCode,
787 generateErrorArguments(aUncPath),
788 xEnv,
789 rtl::OUString(
790 RTL_CONSTASCII_USTRINGPARAM(
791 "a file or directory could not be deleted")),
792 xComProc );
794 else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
795 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
796 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
797 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
798 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
799 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
800 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
801 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
803 rtl::OUString aMsg;
804 switch( minorCode )
806 case FileBase::E_NOENT: // No such file or directory
807 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
808 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
809 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
810 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
812 ioErrorCode = IOErrorCode_NOT_EXISTING;
813 aMsg = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
814 "source file/folder does not exist"));
815 break;
817 else
819 ioErrorCode = IOErrorCode_GENERAL;
820 aMsg = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
821 "a general error during transfer command"));
822 break;
824 default:
825 ioErrorCode = IOErrorCode_GENERAL;
826 aMsg = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
827 "a general error during transfer command"));
828 break;
830 cancelCommandExecution(
831 ioErrorCode,
832 generateErrorArguments(aUncPath),
833 xEnv,
834 aMsg,
835 xComProc );
837 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
839 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
840 cancelCommandExecution(
841 ioErrorCode,
842 generateErrorArguments(aUncPath),
843 xEnv,
844 rtl::OUString(
845 RTL_CONSTASCII_USTRINGPARAM(
846 "accessing the root during transfer")),
847 xComProc );
849 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
851 Reference<XInterface> xContext(xComProc,UNO_QUERY);
853 aAny <<=
854 InteractiveBadTransferURLException(
855 rtl::OUString(
856 RTL_CONSTASCII_USTRINGPARAM(
857 "bad tranfer url")),
858 xContext);
859 cancelCommandExecution( aAny,xEnv );
861 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
862 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
863 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
864 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
865 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
866 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
867 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
868 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
869 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
870 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
872 rtl::OUString aMsg(RTL_CONSTASCII_USTRINGPARAM(
873 "general error during transfer"));
875 switch( minorCode )
877 case FileBase::E_EXIST:
878 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
879 break;
880 case FileBase::E_INVAL: // the format of the parameters was not valid
881 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
882 break;
883 case FileBase::E_NOMEM: // not enough memory for allocating structures
884 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
885 break;
886 case FileBase::E_ACCES: // Permission denied
887 ioErrorCode = IOErrorCode_ACCESS_DENIED;
888 break;
889 case FileBase::E_PERM: // Operation not permitted
890 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
891 break;
892 case FileBase::E_NAMETOOLONG: // File name too long
893 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
894 break;
895 case FileBase::E_NOENT: // No such file or directory
896 ioErrorCode = IOErrorCode_NOT_EXISTING;
897 aMsg = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
898 "file/folder does not exist"));
899 break;
900 case FileBase::E_ROFS: // Read-only file system<p>
901 ioErrorCode = IOErrorCode_NOT_EXISTING;
902 break;
903 default:
904 ioErrorCode = IOErrorCode_GENERAL;
905 break;
907 cancelCommandExecution(
908 ioErrorCode,
909 generateErrorArguments(aUncPath),
910 xEnv,
911 aMsg,
912 xComProc );
914 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
915 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
917 NameClashException excep;
918 excep.Name = getTitle(aUncPath);
919 excep.Classification = InteractionClassification_ERROR;
920 Reference<XInterface> xContext(xComProc,UNO_QUERY);
921 excep.Context = xContext;
922 excep.Message = rtl::OUString(
923 RTL_CONSTASCII_USTRINGPARAM(
924 "name clash during copy or move"));
925 aAny <<= excep;
927 cancelCommandExecution(aAny,xEnv);
929 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
930 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
932 Reference<XInterface> xContext(
933 xComProc,UNO_QUERY);
934 UnsupportedNameClashException excep;
935 excep.NameClash = minorCode;
936 excep.Context = xContext;
937 excep.Message = rtl::OUString(
938 RTL_CONSTASCII_USTRINGPARAM(
939 "name clash value not supported during copy or move"));
941 aAny <<= excep;
942 cancelCommandExecution(aAny,xEnv);
944 else
946 // case TASKHANDLER_NO_ERROR:
947 return;
952 } // end namespace fileaccess