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