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