xref: /aoo42x/main/ucb/source/ucp/file/filglob.cxx (revision 421ed02e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_file.hxx"
26 #include <stdio.h>
27 #include "filglob.hxx"
28 #ifndef _FILERROR_HXX_
29 #include "filerror.hxx"
30 #endif
31 #include "shell.hxx"
32 #include "bc.hxx"
33 #include <osl/file.hxx>
34 #ifndef INCLUDED_STL_VECTOR
35 #include <vector>
36 #define INCLUDED_STL_VECTOR
37 #endif
38 #include <ucbhelper/cancelcommandexecution.hxx>
39 #include <com/sun/star/ucb/CommandAbortedException.hpp>
40 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
41 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
42 #include <com/sun/star/lang/IllegalArgumentException.hpp>
43 #include <com/sun/star/ucb/IOErrorCode.hpp>
44 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
45 #include <com/sun/star/ucb/MissingInputStreamException.hpp>
46 #include <com/sun/star/ucb/NameClashException.hpp>
47 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
48 #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
49 #include "com/sun/star/beans/PropertyState.hpp"
50 #include "com/sun/star/beans/PropertyValue.hpp"
51 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
52 #include "com/sun/star/uno/Any.hxx"
53 #include "com/sun/star/uno/Sequence.hxx"
54 #include "osl/diagnose.h"
55 #include "rtl/ustrbuf.hxx"
56 #include <rtl/uri.hxx>
57 #include <rtl/ustring.hxx>
58 #include "sal/types.h"
59 
60 using namespace ucbhelper;
61 using namespace osl;
62 using namespace ::com::sun::star;
63 using namespace com::sun::star::task;
64 using namespace com::sun::star::beans;
65 using namespace com::sun::star::lang;
66 using namespace com::sun::star::uno;
67 using namespace com::sun::star::ucb;
68 
69 namespace {
70 
generateErrorArguments(rtl::OUString const & rPhysicalUrl)71     Sequence< Any > generateErrorArguments(
72         rtl::OUString const & rPhysicalUrl)
73     {
74         rtl::OUString aResourceName;
75         rtl::OUString aResourceType;
76         sal_Bool      bRemovable;
77         bool bResourceName = false;
78         bool bResourceType = false;
79         bool bRemoveProperty = false;
80 
81         if (osl::FileBase::getSystemPathFromFileURL(
82                 rPhysicalUrl,
83                 aResourceName)
84             == osl::FileBase::E_None)
85             bResourceName = true;
86 
87         // The resource types "folder" (i.e., directory) and
88         // "volume" seem to be
89         // the most interesting when producing meaningful error messages:
90         osl::DirectoryItem aItem;
91         if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
92             osl::FileBase::E_None)
93         {
94             osl::FileStatus aStatus( FileStatusMask_Type );
95             if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
96                 switch (aStatus.getFileType())
97                 {
98                     case osl::FileStatus::Directory:
99                         aResourceType
100                             = rtl::OUString(
101                                 RTL_CONSTASCII_USTRINGPARAM("folder"));
102                         bResourceType = true;
103                         break;
104 
105                     case osl::FileStatus::Volume:
106                     {
107                         aResourceType
108                             = rtl::OUString(
109                                 RTL_CONSTASCII_USTRINGPARAM("volume"));
110                         bResourceType = true;
111                         osl::VolumeInfo aVolumeInfo(
112                             VolumeInfoMask_Attributes );
113                         if( osl::Directory::getVolumeInfo(
114                             rPhysicalUrl,aVolumeInfo ) ==
115                             osl::FileBase::E_None )
116                         {
117                             bRemovable = aVolumeInfo.getRemoveableFlag();
118                             bRemoveProperty = true;
119                         }
120                     }
121                     break;
122                     case osl::FileStatus::Regular:
123                     case osl::FileStatus::Fifo:
124                     case osl::FileStatus::Socket:
125                     case osl::FileStatus::Link:
126                     case osl::FileStatus::Special:
127                     case osl::FileStatus::Unknown:
128                         // do nothing for now
129                         break;
130                 }
131         }
132 
133         Sequence< Any > aArguments( 1              +
134                                     (bResourceName ? 1 : 0)     +
135                                     (bResourceType ? 1 : 0)     +
136                                     (bRemoveProperty ? 1 : 0) );
137         sal_Int32 i = 0;
138         aArguments[i++]
139             <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
140                 "Uri")),
141                               -1,
142                               makeAny(rPhysicalUrl),
143                               PropertyState_DIRECT_VALUE);
144         if (bResourceName)
145             aArguments[i++]
146                 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
147                     "ResourceName")),
148                                   -1,
149                                   makeAny(aResourceName),
150                                   PropertyState_DIRECT_VALUE);
151         if (bResourceType)
152             aArguments[i++]
153                 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
154                     "ResourceType")),
155                                   -1,
156                                   makeAny(aResourceType),
157                                   PropertyState_DIRECT_VALUE);
158         if (bRemoveProperty)
159             aArguments[i++]
160                 <<= PropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
161                     "Removable")),
162                                   -1,
163                                   makeAny(bRemovable),
164                                   PropertyState_DIRECT_VALUE);
165 
166         return aArguments;
167     }
168 }
169 
170 
171 
172 namespace fileaccess {
173 
174 
isChild(const rtl::OUString & srcUnqPath,const rtl::OUString & dstUnqPath)175     sal_Bool isChild( const rtl::OUString& srcUnqPath,
176                       const rtl::OUString& dstUnqPath )
177     {
178         static sal_Unicode slash = '/';
179         // Simple lexical comparison
180         sal_Int32 srcL = srcUnqPath.getLength();
181         sal_Int32 dstL = dstUnqPath.getLength();
182 
183         return (
184             ( srcUnqPath == dstUnqPath )
185             ||
186             ( ( dstL > srcL )
187               &&
188               ( srcUnqPath.compareTo( dstUnqPath, srcL ) == 0 )
189               &&
190               ( dstUnqPath[ srcL ] == slash ) )
191         );
192     }
193 
194 
newName(const rtl::OUString & aNewPrefix,const rtl::OUString & aOldPrefix,const rtl::OUString & old_Name)195     rtl::OUString newName(
196         const rtl::OUString& aNewPrefix,
197         const rtl::OUString& aOldPrefix,
198         const rtl::OUString& old_Name )
199     {
200         sal_Int32 srcL = aOldPrefix.getLength();
201 
202         rtl::OUString new_Name = old_Name.copy( srcL );
203         new_Name = ( aNewPrefix + new_Name );
204         return new_Name;
205     }
206 
207 
getTitle(const rtl::OUString & aPath)208     rtl::OUString getTitle( const rtl::OUString& aPath )
209     {
210         sal_Unicode slash = '/';
211         sal_Int32 lastIndex = aPath.lastIndexOf( slash );
212         return aPath.copy( lastIndex + 1 );
213     }
214 
215 
getParentName(const rtl::OUString & aFileName)216     rtl::OUString getParentName( const rtl::OUString& aFileName )
217     {
218         sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') );
219         rtl::OUString aParent = aFileName.copy( 0,lastIndex );
220 
221         if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 )
222             aParent += rtl::OUString::createFromAscii( "/" );
223 
224         if( 0 == aParent.compareToAscii( "file://" ) )
225             aParent = rtl::OUString::createFromAscii( "file:///" );
226 
227         return aParent;
228     }
229 
230 
osl_File_copy(const rtl::OUString & strPath,const rtl::OUString & strDestPath,sal_Bool test)231     osl::FileBase::RC osl_File_copy( const rtl::OUString& strPath,
232                                      const rtl::OUString& strDestPath,
233                                      sal_Bool test )
234     {
235         if( test )
236         {
237             osl::DirectoryItem aItem;
238             if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
239                 return osl::FileBase::E_EXIST;
240         }
241 
242         return osl::File::copy( strPath,strDestPath );
243     }
244 
245 
osl_File_move(const rtl::OUString & strPath,const rtl::OUString & strDestPath,sal_Bool test)246     osl::FileBase::RC osl_File_move( const rtl::OUString& strPath,
247                                      const rtl::OUString& strDestPath,
248                                      sal_Bool test )
249     {
250         if( test )
251         {
252             osl::DirectoryItem aItem;
253             if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
254                 return osl::FileBase::E_EXIST;
255         }
256 
257         return osl::File::move( strPath,strDestPath );
258     }
259 
throw_handler(sal_Int32 errorCode,sal_Int32 minorCode,const Reference<XCommandEnvironment> & xEnv,const rtl::OUString & aUncPath,BaseContent * pContent,bool isHandled)260     void throw_handler(
261         sal_Int32 errorCode,
262         sal_Int32 minorCode,
263         const Reference< XCommandEnvironment >& xEnv,
264         const rtl::OUString& aUncPath,
265         BaseContent* pContent,
266         bool isHandled )
267     {
268         Reference<XCommandProcessor> xComProc(pContent);
269         Any aAny;
270         IOErrorCode ioErrorCode;
271 
272         if( errorCode ==  TASKHANDLER_UNSUPPORTED_COMMAND )
273         {
274             aAny <<= UnsupportedCommandException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
275             cancelCommandExecution( aAny,xEnv );
276         }
277         else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
278                  errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
279                  errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT              ||
280                  errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT            ||
281                  errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT          ||
282                  errorCode == TASKHANDLING_WRONG_INSERT_ARGUMENT            ||
283                  errorCode == TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT )
284         {
285             IllegalArgumentException excep;
286             excep.ArgumentPosition = 0;
287             aAny <<= excep;
288             cancelCommandExecution(
289                 aAny,xEnv);
290         }
291         else if( errorCode == TASKHANDLING_UNSUPPORTED_OPEN_MODE )
292         {
293             UnsupportedOpenModeException excep;
294             excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
295             aAny <<= excep;
296                 cancelCommandExecution( aAny,xEnv );
297         }
298         else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND  ||
299                 errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
300                 errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
301         {
302             // What to do here?
303         }
304         else if(
305             // error in opening file
306             errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
307             // error in opening file
308             errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE     ||
309             // error in opening file
310             errorCode == TASKHANDLING_OPEN_FOR_STREAM            ||
311             // error in opening file
312             errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM       ||
313             // error in opening file
314             errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
315         {
316             switch( minorCode )
317             {
318                 case FileBase::E_NAMETOOLONG:
319                     // pathname was too long
320                     ioErrorCode = IOErrorCode_NAME_TOO_LONG;
321                     break;
322                 case FileBase::E_NXIO:
323                     // No such device or address
324                 case FileBase::E_NODEV:
325                     // No such device
326                     ioErrorCode = IOErrorCode_INVALID_DEVICE;
327                     break;
328                 case FileBase::E_NOENT:
329                     // No such file or directory
330                     ioErrorCode = IOErrorCode_NOT_EXISTING;
331                     break;
332                 case FileBase::E_ROFS:
333                     // #i4735# handle ROFS transparently as ACCESS_DENIED
334                 case FileBase::E_ACCES:
335                     // permission denied<P>
336                     ioErrorCode = IOErrorCode_ACCESS_DENIED;
337                     break;
338                 case FileBase::E_ISDIR:
339                     // Is a directory<p>
340                     ioErrorCode = IOErrorCode_NO_FILE;
341                     break;
342                 case FileBase::E_NOTREADY:
343                     ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
344                     break;
345                 case FileBase::E_MFILE:
346                     // too many open files used by the process
347                 case FileBase::E_NFILE:
348                     // too many open files in the system
349                     ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
350                     break;
351                 case FileBase::E_INVAL:
352                     // the format of the parameters was not valid
353                     ioErrorCode = IOErrorCode_INVALID_PARAMETER;
354                     break;
355                 case FileBase::E_NOMEM:
356                     // not enough memory for allocating structures
357                     ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
358                     break;
359                 case FileBase::E_BUSY:
360                     // Text file busy
361                     ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
362                     break;
363                 case FileBase::E_AGAIN:
364                     // Operation would block
365                     ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
366                     break;
367                 case FileBase::E_NOLCK:  // No record locks available
368                     ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
369                     break;
370 
371                 case FileBase::E_LOCKED:  // file is locked by another user
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 occurred 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 occurred 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 occurred 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 occurred 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 transfer 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