LCOV - code coverage report
Current view: top level - ucb/source/ucp/file - filglob.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 140 383 36.6 %
Date: 2014-11-03 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10