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