merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / file / filglob.cxx
blob26392425cf1f3340e00da627113ff57d36519d60
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;
365 case FileBase::E_BUSY:
366 // Text file busy
367 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
368 break;
369 case FileBase::E_AGAIN:
370 // Operation would block
371 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
372 break;
373 case FileBase::E_NOLCK: // No record locks available
374 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
375 break;
377 case FileBase::E_FAULT: // Bad address
378 case FileBase::E_LOOP: // Too many symbolic links encountered
379 case FileBase::E_NOSPC: // No space left on device
380 case FileBase::E_INTR: // function call was interrupted
381 case FileBase::E_IO: // I/O error
382 case FileBase::E_MULTIHOP: // Multihop attempted
383 case FileBase::E_NOLINK: // Link has been severed
384 default:
385 ioErrorCode = IOErrorCode_GENERAL;
386 break;
389 cancelCommandExecution(
390 ioErrorCode,
391 generateErrorArguments(aUncPath),
392 xEnv,
393 rtl::OUString(
394 RTL_CONSTASCII_USTRINGPARAM(
395 "an error occured during file opening")),
396 xComProc);
398 else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
399 errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
401 switch( minorCode )
403 case FileBase::E_INVAL:
404 // the format of the parameters was not valid
405 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
406 break;
407 case FileBase::E_NOENT:
408 // the specified path doesn't exist
409 ioErrorCode = IOErrorCode_NOT_EXISTING;
410 break;
411 case FileBase::E_NOTDIR:
412 // the specified path is not an directory
413 ioErrorCode = IOErrorCode_NO_DIRECTORY;
414 break;
415 case FileBase::E_NOMEM:
416 // not enough memory for allocating structures
417 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
418 break;
419 case FileBase::E_ROFS:
420 // #i4735# handle ROFS transparently as ACCESS_DENIED
421 case FileBase::E_ACCES: // permission denied
422 ioErrorCode = IOErrorCode_ACCESS_DENIED;
423 break;
424 case FileBase::E_NOTREADY:
425 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
426 break;
427 case FileBase::E_MFILE:
428 // too many open files used by the process
429 case FileBase::E_NFILE:
430 // too many open files in the system
431 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
432 break;
433 case FileBase::E_NAMETOOLONG:
434 // File name too long
435 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
436 break;
437 case FileBase::E_LOOP:
438 // Too many symbolic links encountered<p>
439 default:
440 ioErrorCode = IOErrorCode_GENERAL;
441 break;
444 cancelCommandExecution(
445 ioErrorCode,
446 generateErrorArguments(aUncPath),
447 xEnv,
448 rtl::OUString(
449 RTL_CONSTASCII_USTRINGPARAM(
450 "an error occured during opening a directory")),
451 xComProc);
453 else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
454 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
455 errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
456 errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
457 errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING ||
458 errorCode == TASKHANDLING_IOEXCEPTION_FOR_PAGING )
460 ioErrorCode = IOErrorCode_UNKNOWN;
461 cancelCommandExecution(
462 ioErrorCode,
463 generateErrorArguments(aUncPath),
464 xEnv,
465 rtl::OUString(
466 RTL_CONSTASCII_USTRINGPARAM(
467 "an error occured writing or reading from a file")),
468 xComProc );
470 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_NO_SPACE )
472 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
473 cancelCommandExecution(
474 ioErrorCode,
475 generateErrorArguments(aUncPath),
476 xEnv,
477 rtl::OUString(
478 RTL_CONSTASCII_USTRINGPARAM(
479 "device full")),
480 xComProc);
482 else if( errorCode == TASKHANDLING_FILEIOERROR_FOR_WRITE ||
483 errorCode == TASKHANDLING_READING_FILE_FOR_PAGING )
485 switch( minorCode )
487 case FileBase::E_INVAL:
488 // the format of the parameters was not valid
489 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
490 break;
491 case FileBase::E_FBIG:
492 // File too large
493 ioErrorCode = IOErrorCode_CANT_WRITE;
494 break;
495 case FileBase::E_NOSPC:
496 // No space left on device
497 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
498 break;
499 case FileBase::E_NXIO:
500 // No such device or address
501 ioErrorCode = IOErrorCode_INVALID_DEVICE;
502 break;
503 case FileBase::E_NOLINK:
504 // Link has been severed
505 case FileBase::E_ISDIR:
506 // Is a directory
507 ioErrorCode = IOErrorCode_NO_FILE;
508 break;
509 case FileBase::E_AGAIN:
510 // Operation would block
511 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
512 break;
513 case FileBase::E_TIMEDOUT:
514 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
515 break;
516 case FileBase::E_NOLCK: // No record locks available
517 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
518 break;
519 case FileBase::E_IO: // I/O error
520 case FileBase::E_BADF: // Bad file
521 case FileBase::E_FAULT: // Bad address
522 case FileBase::E_INTR: // function call was interrupted
523 default:
524 ioErrorCode = IOErrorCode_GENERAL;
525 break;
527 cancelCommandExecution(
528 ioErrorCode,
529 generateErrorArguments(aUncPath),
530 xEnv,
531 rtl::OUString(
532 RTL_CONSTASCII_USTRINGPARAM(
533 "an error occured during opening a file")),
534 xComProc);
536 else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
537 errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
539 Sequence< ::rtl::OUString > aSeq( 1 );
540 aSeq[0] =
541 ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
542 rtl::OUString::createFromAscii( "Title" ) :
543 rtl::OUString::createFromAscii( "ContentType" );
545 aAny <<= MissingPropertiesException(
546 rtl::OUString(
547 RTL_CONSTASCII_USTRINGPARAM(
548 "a property is missing necessary"
549 "to create a content")),
550 xComProc,
551 aSeq);
552 cancelCommandExecution(aAny,xEnv);
554 else if( errorCode == TASKHANDLING_FILESIZE_FOR_WRITE )
556 switch( minorCode )
558 case FileBase::E_INVAL:
559 // the format of the parameters was not valid
560 case FileBase::E_OVERFLOW:
561 // The resulting file offset would be a value which cannot
562 // be represented correctly for regular files
563 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
564 break;
565 default:
566 ioErrorCode = IOErrorCode_GENERAL;
567 break;
569 cancelCommandExecution(
570 ioErrorCode,
571 generateErrorArguments(aUncPath),
572 xEnv,
573 rtl::OUString(
574 RTL_CONSTASCII_USTRINGPARAM(
575 "there were problems with the filesize")),
576 xComProc);
578 else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
580 Reference<XInterface> xContext(xComProc,UNO_QUERY);
581 aAny <<=
582 MissingInputStreamException(
583 rtl::OUString(
584 RTL_CONSTASCII_USTRINGPARAM(
585 "the inputstream is missing necessary"
586 "to create a content")),
587 xContext);
588 cancelCommandExecution(aAny,xEnv);
590 else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
591 // Overwrite = false and file exists
593 NameClashException excep;
594 excep.Name = getTitle(aUncPath);
595 excep.Classification = InteractionClassification_ERROR;
596 Reference<XInterface> xContext(xComProc,UNO_QUERY);
597 excep.Context = xContext;
598 excep.Message = rtl::OUString(
599 RTL_CONSTASCII_USTRINGPARAM(
600 "file exists and overwrite forbidden"));
601 aAny <<= excep;
602 cancelCommandExecution( aAny,xEnv );
604 else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
606 InteractiveAugmentedIOException excep;
607 excep.Code = IOErrorCode_INVALID_CHARACTER;
608 PropertyValue prop;
609 prop.Name = rtl::OUString::createFromAscii("ResourceName");
610 prop.Handle = -1;
611 rtl::OUString m_aClashingName(
612 rtl::Uri::decode(
613 getTitle(aUncPath),
614 rtl_UriDecodeWithCharset,
615 RTL_TEXTENCODING_UTF8));
616 prop.Value <<= m_aClashingName;
617 Sequence<Any> seq(1);
618 seq[0] <<= prop;
619 excep.Arguments = seq;
620 excep.Classification = InteractionClassification_ERROR;
621 Reference<XInterface> xContext(xComProc,UNO_QUERY);
622 excep.Context = xContext;
623 excep.Message = rtl::OUString(
624 RTL_CONSTASCII_USTRINGPARAM(
625 "the name contained invalid characters"));
626 if(isHandled)
627 throw excep;
628 else {
629 aAny <<= excep;
630 cancelCommandExecution( aAny,xEnv );
632 // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
633 // cancelCommandExecution(
634 // ioErrorCode,
635 // generateErrorArguments(aUncPath),
636 // xEnv,
637 // rtl::OUString(
638 // RTL_CONSTASCII_USTRINGPARAM(
639 // "the name contained invalid characters")),
640 // xComProc );
642 else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
644 NameClashException excep;
645 excep.Name = getTitle(aUncPath);
646 excep.Classification = InteractionClassification_ERROR;
647 Reference<XInterface> xContext(xComProc,UNO_QUERY);
648 excep.Context = xContext;
649 excep.Message = rtl::OUString(
650 RTL_CONSTASCII_USTRINGPARAM(
651 "folder exists and overwrite forbidden"));
652 if(isHandled)
653 throw excep;
654 else {
655 aAny <<= excep;
656 cancelCommandExecution( aAny,xEnv );
658 // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
659 // cancelCommandExecution(
660 // ioErrorCode,
661 // generateErrorArguments(aUncPath),
662 // xEnv,
663 // rtl::OUString(
664 // RTL_CONSTASCII_USTRINGPARAM(
665 // "the folder exists")),
666 // xComProc );
668 else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
669 errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
671 switch( minorCode )
673 case FileBase::E_ACCES:
674 ioErrorCode = IOErrorCode_ACCESS_DENIED;
675 break;
676 case FileBase::E_ROFS:
677 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
678 break;
679 case FileBase::E_NAMETOOLONG:
680 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
681 break;
682 default:
683 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
684 break;
686 cancelCommandExecution(
687 ioErrorCode,
688 generateErrorArguments(getParentName(aUncPath)),
689 //TODO! ok to supply physical URL to getParentName()?
690 xEnv,
691 rtl::OUString(
692 RTL_CONSTASCII_USTRINGPARAM(
693 "a folder could not be created")),
694 xComProc );
696 else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
697 errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
698 errorCode == TASKHANDLING_NOSUCHFILEORDIR_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_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
709 case FileBase::E_ACCES: // permission denied
710 ioErrorCode = IOErrorCode_ACCESS_DENIED;
711 break;
712 case FileBase::E_MFILE: // too many open files used by the process
713 case FileBase::E_NFILE: // too many open files in the system
714 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
715 break;
716 case FileBase::E_NOLINK: // Link has been severed
717 case FileBase::E_NOENT: // No such file or directory
718 ioErrorCode = IOErrorCode_NOT_EXISTING;
719 break;
720 case FileBase::E_NAMETOOLONG: // File name too long
721 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
722 break;
723 case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
724 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
725 break;
726 case FileBase::E_LOOP: // Too many symbolic links encountered
727 case FileBase::E_IO: // I/O error
728 case FileBase::E_MULTIHOP: // Multihop attempted
729 case FileBase::E_FAULT: // Bad address
730 case FileBase::E_INTR: // function call was interrupted
731 case FileBase::E_NOSYS: // Function not implemented
732 case FileBase::E_NOSPC: // No space left on device
733 case FileBase::E_NXIO: // No such device or address
734 case FileBase::E_OVERFLOW: // Value too large for defined data type
735 case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
736 default:
737 ioErrorCode = IOErrorCode_GENERAL;
738 break;
740 cancelCommandExecution(
741 ioErrorCode,
742 generateErrorArguments(aUncPath),
743 xEnv,
744 rtl::OUString(
745 RTL_CONSTASCII_USTRINGPARAM(
746 "a file status object could not be filled")),
747 xComProc );
749 else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
750 errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
752 switch( minorCode )
754 case FileBase::E_INVAL: // the format of the parameters was not valid
755 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
756 break;
757 case FileBase::E_NOMEM: // not enough memory for allocating structures
758 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
759 break;
760 case FileBase::E_ACCES: // Permission denied
761 ioErrorCode = IOErrorCode_ACCESS_DENIED;
762 break;
763 case FileBase::E_PERM: // Operation not permitted
764 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
765 break;
766 case FileBase::E_NAMETOOLONG: // File name too long
767 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
768 break;
769 case FileBase::E_NOLINK: // Link has been severed
770 case FileBase::E_NOENT: // No such file or directory
771 ioErrorCode = IOErrorCode_NOT_EXISTING;
772 break;
773 case FileBase::E_ISDIR: // Is a directory
774 case FileBase::E_ROFS: // Read-only file system
775 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
776 break;
777 case FileBase::E_BUSY: // Device or resource busy
778 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
779 break;
780 case FileBase::E_FAULT: // Bad address
781 case FileBase::E_LOOP: // Too many symbolic links encountered
782 case FileBase::E_IO: // I/O error
783 case FileBase::E_INTR: // function call was interrupted
784 case FileBase::E_MULTIHOP: // Multihop attempted
785 default:
786 ioErrorCode = IOErrorCode_GENERAL;
787 break;
789 cancelCommandExecution(
790 ioErrorCode,
791 generateErrorArguments(aUncPath),
792 xEnv,
793 rtl::OUString(
794 RTL_CONSTASCII_USTRINGPARAM(
795 "a file or directory could not be deleted")),
796 xComProc );
798 else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
799 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
800 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
801 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
802 errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
803 errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
804 errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
805 errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
807 rtl::OUString aMsg;
808 switch( minorCode )
810 case FileBase::E_NOENT: // No such file or directory
811 if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
812 errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
813 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
814 errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
816 ioErrorCode = IOErrorCode_NOT_EXISTING;
817 aMsg = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
818 "source file/folder does not exist"));
819 break;
821 else
823 ioErrorCode = IOErrorCode_GENERAL;
824 aMsg = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
825 "a general error during transfer command"));
826 break;
828 default:
829 ioErrorCode = IOErrorCode_GENERAL;
830 aMsg = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
831 "a general error during transfer command"));
832 break;
834 cancelCommandExecution(
835 ioErrorCode,
836 generateErrorArguments(aUncPath),
837 xEnv,
838 aMsg,
839 xComProc );
841 else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
843 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
844 cancelCommandExecution(
845 ioErrorCode,
846 generateErrorArguments(aUncPath),
847 xEnv,
848 rtl::OUString(
849 RTL_CONSTASCII_USTRINGPARAM(
850 "accessing the root during transfer")),
851 xComProc );
853 else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
855 Reference<XInterface> xContext(xComProc,UNO_QUERY);
857 aAny <<=
858 InteractiveBadTransferURLException(
859 rtl::OUString(
860 RTL_CONSTASCII_USTRINGPARAM(
861 "bad tranfer url")),
862 xContext);
863 cancelCommandExecution( aAny,xEnv );
865 else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
866 errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
867 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
868 errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
869 errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
870 errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
871 errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
872 errorCode == TASKHANDLING_RENAME_FOR_COPY ||
873 errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
874 errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
876 rtl::OUString aMsg(RTL_CONSTASCII_USTRINGPARAM(
877 "general error during transfer"));
879 switch( minorCode )
881 case FileBase::E_EXIST:
882 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
883 break;
884 case FileBase::E_INVAL: // the format of the parameters was not valid
885 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
886 break;
887 case FileBase::E_NOMEM: // not enough memory for allocating structures
888 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
889 break;
890 case FileBase::E_ACCES: // Permission denied
891 ioErrorCode = IOErrorCode_ACCESS_DENIED;
892 break;
893 case FileBase::E_PERM: // Operation not permitted
894 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
895 break;
896 case FileBase::E_NAMETOOLONG: // File name too long
897 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
898 break;
899 case FileBase::E_NOENT: // No such file or directory
900 ioErrorCode = IOErrorCode_NOT_EXISTING;
901 aMsg = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
902 "file/folder does not exist"));
903 break;
904 case FileBase::E_ROFS: // Read-only file system<p>
905 ioErrorCode = IOErrorCode_NOT_EXISTING;
906 break;
907 default:
908 ioErrorCode = IOErrorCode_GENERAL;
909 break;
911 cancelCommandExecution(
912 ioErrorCode,
913 generateErrorArguments(aUncPath),
914 xEnv,
915 aMsg,
916 xComProc );
918 else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
919 errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
921 NameClashException excep;
922 excep.Name = getTitle(aUncPath);
923 excep.Classification = InteractionClassification_ERROR;
924 Reference<XInterface> xContext(xComProc,UNO_QUERY);
925 excep.Context = xContext;
926 excep.Message = rtl::OUString(
927 RTL_CONSTASCII_USTRINGPARAM(
928 "name clash during copy or move"));
929 aAny <<= excep;
931 cancelCommandExecution(aAny,xEnv);
933 else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
934 errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
936 Reference<XInterface> xContext(
937 xComProc,UNO_QUERY);
938 UnsupportedNameClashException excep;
939 excep.NameClash = minorCode;
940 excep.Context = xContext;
941 excep.Message = rtl::OUString(
942 RTL_CONSTASCII_USTRINGPARAM(
943 "name clash value not supported during copy or move"));
945 aAny <<= excep;
946 cancelCommandExecution(aAny,xEnv);
948 else
950 // case TASKHANDLER_NO_ERROR:
951 return;
956 } // end namespace fileaccess