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 2086 : Sequence< Any > generateErrorArguments(
61 : rtl::OUString const & rPhysicalUrl)
62 : {
63 2086 : rtl::OUString aResourceName;
64 2086 : rtl::OUString aResourceType;
65 : sal_Bool bRemovable;
66 2086 : bool bResourceName = false;
67 2086 : bool bResourceType = false;
68 2086 : bool bRemoveProperty = false;
69 :
70 2086 : if (osl::FileBase::getSystemPathFromFileURL(
71 : rPhysicalUrl,
72 2086 : aResourceName)
73 : == osl::FileBase::E_None)
74 2086 : 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 2086 : osl::DirectoryItem aItem;
80 2086 : if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
81 : osl::FileBase::E_None)
82 : {
83 0 : osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
84 0 : if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
85 0 : switch (aStatus.getFileType())
86 : {
87 : case osl::FileStatus::Directory:
88 0 : aResourceType = rtl::OUString( "folder");
89 0 : bResourceType = true;
90 0 : break;
91 :
92 : case osl::FileStatus::Volume:
93 : {
94 0 : aResourceType = rtl::OUString( "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 0 : break;
115 0 : }
116 : }
117 :
118 : Sequence< Any > aArguments( 1 +
119 : (bResourceName ? 1 : 0) +
120 : (bResourceType ? 1 : 0) +
121 2086 : (bRemoveProperty ? 1 : 0) );
122 2086 : sal_Int32 i = 0;
123 2086 : aArguments[i++]
124 : <<= PropertyValue(rtl::OUString( "Uri"),
125 : -1,
126 : makeAny(rPhysicalUrl),
127 4172 : PropertyState_DIRECT_VALUE);
128 2086 : if (bResourceName)
129 2086 : aArguments[i++]
130 : <<= PropertyValue(rtl::OUString( "ResourceName"),
131 : -1,
132 : makeAny(aResourceName),
133 4172 : PropertyState_DIRECT_VALUE);
134 2086 : if (bResourceType)
135 0 : aArguments[i++]
136 : <<= PropertyValue(rtl::OUString( "ResourceType"),
137 : -1,
138 : makeAny(aResourceType),
139 0 : PropertyState_DIRECT_VALUE);
140 2086 : if (bRemoveProperty)
141 0 : aArguments[i++]
142 : <<= PropertyValue(rtl::OUString( "Removable"),
143 : -1,
144 : makeAny(bRemovable),
145 0 : PropertyState_DIRECT_VALUE);
146 :
147 2086 : return aArguments;
148 : }
149 : }
150 :
151 :
152 :
153 : namespace fileaccess {
154 :
155 :
156 0 : sal_Bool isChild( const rtl::OUString& srcUnqPath,
157 : const rtl::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 : ||
167 : ( ( dstL > srcL )
168 : &&
169 0 : ( srcUnqPath.compareTo( dstUnqPath, srcL ) == 0 )
170 : &&
171 0 : ( dstUnqPath[ srcL ] == slash ) )
172 0 : );
173 : }
174 :
175 :
176 0 : rtl::OUString newName(
177 : const rtl::OUString& aNewPrefix,
178 : const rtl::OUString& aOldPrefix,
179 : const rtl::OUString& old_Name )
180 : {
181 0 : sal_Int32 srcL = aOldPrefix.getLength();
182 :
183 0 : rtl::OUString new_Name = old_Name.copy( srcL );
184 0 : new_Name = ( aNewPrefix + new_Name );
185 0 : return new_Name;
186 : }
187 :
188 :
189 73 : rtl::OUString getTitle( const rtl::OUString& aPath )
190 : {
191 73 : sal_Unicode slash = '/';
192 73 : sal_Int32 lastIndex = aPath.lastIndexOf( slash );
193 73 : return aPath.copy( lastIndex + 1 );
194 : }
195 :
196 :
197 470 : rtl::OUString getParentName( const rtl::OUString& aFileName )
198 : {
199 470 : sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') );
200 470 : rtl::OUString aParent = aFileName.copy( 0,lastIndex );
201 :
202 470 : if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 )
203 0 : aParent += rtl::OUString("/");
204 :
205 470 : if ( aParent == "file://" )
206 0 : aParent = rtl::OUString("file:///");
207 :
208 470 : return aParent;
209 : }
210 :
211 :
212 340 : osl::FileBase::RC osl_File_copy( const rtl::OUString& strPath,
213 : const rtl::OUString& strDestPath,
214 : sal_Bool test )
215 : {
216 340 : 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 340 : return osl::File::copy( strPath,strDestPath );
224 : }
225 :
226 :
227 0 : osl::FileBase::RC osl_File_move( const rtl::OUString& strPath,
228 : const rtl::OUString& strDestPath,
229 : sal_Bool test )
230 : {
231 0 : if( test )
232 : {
233 0 : osl::DirectoryItem aItem;
234 0 : if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
235 0 : return osl::FileBase::E_EXIST;
236 : }
237 :
238 0 : return osl::File::move( strPath,strDestPath );
239 : }
240 :
241 2151 : void throw_handler(
242 : sal_Int32 errorCode,
243 : sal_Int32 minorCode,
244 : const Reference< XCommandEnvironment >& xEnv,
245 : const rtl::OUString& aUncPath,
246 : BaseContent* pContent,
247 : bool isHandled )
248 : {
249 2151 : Reference<XCommandProcessor> xComProc(pContent);
250 2151 : Any aAny;
251 : IOErrorCode ioErrorCode;
252 :
253 2151 : if( errorCode == TASKHANDLER_UNSUPPORTED_COMMAND )
254 : {
255 0 : aAny <<= UnsupportedCommandException( ::rtl::OUString( OSL_LOG_PREFIX ), uno::Reference< uno::XInterface >() );
256 0 : cancelCommandExecution( aAny,xEnv );
257 : }
258 2151 : else if( errorCode == TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT ||
259 : errorCode == TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT ||
260 : errorCode == TASKHANDLING_WRONG_OPEN_ARGUMENT ||
261 : errorCode == TASKHANDLING_WRONG_DELETE_ARGUMENT ||
262 : errorCode == TASKHANDLING_WRONG_TRANSFER_ARGUMENT ||
263 : 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 2151 : 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 2151 : else if(errorCode == TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND ||
280 : errorCode == TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND ||
281 : errorCode == TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND )
282 : {
283 : // What to do here?
284 : }
285 2151 : else if(
286 : // error in opening file
287 : errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE ||
288 : // error in opening file
289 : errorCode == TASKHANDLING_NO_OPEN_FILE_FOR_WRITE ||
290 : // error in opening file
291 : errorCode == TASKHANDLING_OPEN_FOR_STREAM ||
292 : // error in opening file
293 : errorCode == TASKHANDLING_OPEN_FOR_INPUTSTREAM ||
294 : // error in opening file
295 : errorCode == TASKHANDLING_OPEN_FILE_FOR_PAGING )
296 : {
297 2020 : 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 2020 : ioErrorCode = IOErrorCode_NOT_EXISTING;
315 2020 : 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 0 : ioErrorCode = IOErrorCode_GENERAL;
364 0 : break;
365 : }
366 :
367 : cancelCommandExecution(
368 : ioErrorCode,
369 : generateErrorArguments(aUncPath),
370 : xEnv,
371 : rtl::OUString( "an error occurred during file opening"),
372 4040 : xComProc);
373 : }
374 131 : else if( errorCode == TASKHANDLING_OPEN_FOR_DIRECTORYLISTING ||
375 : errorCode == TASKHANDLING_OPENDIRECTORY_FOR_REMOVE )
376 : {
377 5 : 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 5 : ioErrorCode = IOErrorCode_NOT_EXISTING;
386 5 : 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 : rtl::OUString( "an error occurred during opening a directory"),
425 10 : xComProc);
426 : }
427 126 : else if( errorCode == TASKHANDLING_NOTCONNECTED_FOR_WRITE ||
428 : errorCode == TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE ||
429 : errorCode == TASKHANDLING_IOEXCEPTION_FOR_WRITE ||
430 : errorCode == TASKHANDLING_NOTCONNECTED_FOR_PAGING ||
431 : 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 : rtl::OUString( "an error occurred writing or reading from a file"),
440 0 : xComProc );
441 : }
442 126 : 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 : rtl::OUString( "device full"),
450 0 : xComProc);
451 : }
452 126 : 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 : rtl::OUString( "an error occurred during opening a file"),
502 0 : xComProc);
503 : }
504 126 : else if( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ||
505 : errorCode == TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND )
506 : {
507 0 : Sequence< ::rtl::OUString > aSeq( 1 );
508 0 : aSeq[0] =
509 : ( errorCode == TASKHANDLING_NONAMESET_INSERT_COMMAND ) ?
510 : rtl::OUString("Title") :
511 0 : rtl::OUString("ContentType");
512 :
513 : aAny <<= MissingPropertiesException(
514 : rtl::OUString( "a property is missing necessary"
515 : "to create a content"),
516 : xComProc,
517 0 : aSeq);
518 0 : cancelCommandExecution(aAny,xEnv);
519 : }
520 126 : 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 : rtl::OUString( "there were problems with the filesize"),
540 0 : xComProc);
541 : }
542 126 : else if(errorCode == TASKHANDLING_INPUTSTREAM_FOR_WRITE)
543 : {
544 0 : Reference<XInterface> xContext(xComProc,UNO_QUERY);
545 : aAny <<=
546 : MissingInputStreamException(
547 : rtl::OUString( "the inputstream is missing necessary"
548 : "to create a content"),
549 0 : xContext);
550 0 : cancelCommandExecution(aAny,xEnv);
551 : }
552 126 : else if( errorCode == TASKHANDLING_NOREPLACE_FOR_WRITE )
553 : // Overwrite = false and file exists
554 : {
555 57 : NameClashException excep;
556 57 : excep.Name = getTitle(aUncPath);
557 57 : excep.Classification = InteractionClassification_ERROR;
558 57 : Reference<XInterface> xContext(xComProc,UNO_QUERY);
559 57 : excep.Context = xContext;
560 57 : excep.Message = rtl::OUString( "file exists and overwrite forbidden");
561 57 : aAny <<= excep;
562 114 : cancelCommandExecution( aAny,xEnv );
563 : }
564 69 : else if( errorCode == TASKHANDLING_INVALID_NAME_MKDIR )
565 : {
566 0 : InteractiveAugmentedIOException excep;
567 0 : excep.Code = IOErrorCode_INVALID_CHARACTER;
568 0 : PropertyValue prop;
569 0 : prop.Name = rtl::OUString("ResourceName");
570 0 : prop.Handle = -1;
571 : rtl::OUString m_aClashingName(
572 : rtl::Uri::decode(
573 : getTitle(aUncPath),
574 : rtl_UriDecodeWithCharset,
575 0 : RTL_TEXTENCODING_UTF8));
576 0 : prop.Value <<= m_aClashingName;
577 0 : Sequence<Any> seq(1);
578 0 : seq[0] <<= prop;
579 0 : excep.Arguments = seq;
580 0 : excep.Classification = InteractionClassification_ERROR;
581 0 : Reference<XInterface> xContext(xComProc,UNO_QUERY);
582 0 : excep.Context = xContext;
583 0 : excep.Message = rtl::OUString( "the name contained invalid characters");
584 0 : if(isHandled)
585 0 : throw excep;
586 : else {
587 0 : aAny <<= excep;
588 0 : cancelCommandExecution( aAny,xEnv );
589 0 : }
590 : // ioErrorCode = IOErrorCode_INVALID_CHARACTER;
591 : // cancelCommandExecution(
592 : // ioErrorCode,
593 : // generateErrorArguments(aUncPath),
594 : // xEnv,
595 : // rtl::OUString( "the name contained invalid characters"),
596 : // xComProc );
597 : }
598 69 : else if( errorCode == TASKHANDLING_FOLDER_EXISTS_MKDIR )
599 : {
600 8 : NameClashException excep;
601 8 : excep.Name = getTitle(aUncPath);
602 8 : excep.Classification = InteractionClassification_ERROR;
603 8 : Reference<XInterface> xContext(xComProc,UNO_QUERY);
604 8 : excep.Context = xContext;
605 8 : excep.Message = rtl::OUString( "folder exists and overwrite forbidden");
606 8 : if(isHandled)
607 8 : throw excep;
608 : else {
609 0 : aAny <<= excep;
610 0 : cancelCommandExecution( aAny,xEnv );
611 8 : }
612 : // ioErrorCode = IOErrorCode_ALREADY_EXISTING;
613 : // cancelCommandExecution(
614 : // ioErrorCode,
615 : // generateErrorArguments(aUncPath),
616 : // xEnv,
617 : // rtl::OUString( "the folder exists"),
618 : // xComProc );
619 : }
620 61 : else if( errorCode == TASKHANDLING_ENSUREDIR_FOR_WRITE ||
621 : errorCode == TASKHANDLING_CREATEDIRECTORY_MKDIR )
622 : {
623 0 : switch( minorCode )
624 : {
625 : case FileBase::E_ACCES:
626 0 : ioErrorCode = IOErrorCode_ACCESS_DENIED;
627 0 : break;
628 : case FileBase::E_ROFS:
629 0 : ioErrorCode = IOErrorCode_WRITE_PROTECTED;
630 0 : break;
631 : case FileBase::E_NAMETOOLONG:
632 0 : ioErrorCode = IOErrorCode_NAME_TOO_LONG;
633 0 : break;
634 : default:
635 0 : ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
636 0 : break;
637 : }
638 : cancelCommandExecution(
639 : ioErrorCode,
640 : generateErrorArguments(getParentName(aUncPath)),
641 : //TODO! ok to supply physical URL to getParentName()?
642 : xEnv,
643 : rtl::OUString( "a folder could not be created"),
644 0 : xComProc );
645 : }
646 61 : else if( errorCode == TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE ||
647 : errorCode == TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE ||
648 : errorCode == TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE )
649 : {
650 2 : switch( minorCode )
651 : {
652 : case FileBase::E_INVAL: // the format of the parameters was not valid
653 0 : ioErrorCode = IOErrorCode_INVALID_PARAMETER;
654 0 : break;
655 : case FileBase::E_NOMEM: // not enough memory for allocating structures
656 0 : ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
657 0 : break;
658 : case FileBase::E_ROFS: // #i4735# handle ROFS transparently as ACCESS_DENIED
659 : case FileBase::E_ACCES: // permission denied
660 0 : ioErrorCode = IOErrorCode_ACCESS_DENIED;
661 0 : break;
662 : case FileBase::E_MFILE: // too many open files used by the process
663 : case FileBase::E_NFILE: // too many open files in the system
664 0 : ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
665 0 : break;
666 : case FileBase::E_NOLINK: // Link has been severed
667 : case FileBase::E_NOENT: // No such file or directory
668 2 : ioErrorCode = IOErrorCode_NOT_EXISTING;
669 2 : break;
670 : case FileBase::E_NAMETOOLONG: // File name too long
671 0 : ioErrorCode = IOErrorCode_NAME_TOO_LONG;
672 0 : break;
673 : case FileBase::E_NOTDIR: // A component of the path prefix of path is not a directory
674 0 : ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
675 0 : break;
676 : case FileBase::E_LOOP: // Too many symbolic links encountered
677 : case FileBase::E_IO: // I/O error
678 : case FileBase::E_MULTIHOP: // Multihop attempted
679 : case FileBase::E_FAULT: // Bad address
680 : case FileBase::E_INTR: // function call was interrupted
681 : case FileBase::E_NOSYS: // Function not implemented
682 : case FileBase::E_NOSPC: // No space left on device
683 : case FileBase::E_NXIO: // No such device or address
684 : case FileBase::E_OVERFLOW: // Value too large for defined data type
685 : case FileBase::E_BADF: // Invalid oslDirectoryItem parameter
686 : default:
687 0 : ioErrorCode = IOErrorCode_GENERAL;
688 0 : break;
689 : }
690 : cancelCommandExecution(
691 : ioErrorCode,
692 : generateErrorArguments(aUncPath),
693 : xEnv,
694 : rtl::OUString( "a file status object could not be filled"),
695 4 : xComProc );
696 : }
697 59 : else if( errorCode == TASKHANDLING_DELETEFILE_FOR_REMOVE ||
698 : errorCode == TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE )
699 : {
700 0 : switch( minorCode )
701 : {
702 : case FileBase::E_INVAL: // the format of the parameters was not valid
703 0 : ioErrorCode = IOErrorCode_INVALID_PARAMETER;
704 0 : break;
705 : case FileBase::E_NOMEM: // not enough memory for allocating structures
706 0 : ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
707 0 : break;
708 : case FileBase::E_ACCES: // Permission denied
709 0 : ioErrorCode = IOErrorCode_ACCESS_DENIED;
710 0 : break;
711 : case FileBase::E_PERM: // Operation not permitted
712 0 : ioErrorCode = IOErrorCode_NOT_SUPPORTED;
713 0 : break;
714 : case FileBase::E_NAMETOOLONG: // File name too long
715 0 : ioErrorCode = IOErrorCode_NAME_TOO_LONG;
716 0 : break;
717 : case FileBase::E_NOLINK: // Link has been severed
718 : case FileBase::E_NOENT: // No such file or directory
719 0 : ioErrorCode = IOErrorCode_NOT_EXISTING;
720 0 : break;
721 : case FileBase::E_ISDIR: // Is a directory
722 : case FileBase::E_ROFS: // Read-only file system
723 0 : ioErrorCode = IOErrorCode_NOT_SUPPORTED;
724 0 : break;
725 : case FileBase::E_BUSY: // Device or resource busy
726 0 : ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
727 0 : break;
728 : case FileBase::E_FAULT: // Bad address
729 : case FileBase::E_LOOP: // Too many symbolic links encountered
730 : case FileBase::E_IO: // I/O error
731 : case FileBase::E_INTR: // function call was interrupted
732 : case FileBase::E_MULTIHOP: // Multihop attempted
733 : default:
734 0 : ioErrorCode = IOErrorCode_GENERAL;
735 0 : break;
736 : }
737 : cancelCommandExecution(
738 : ioErrorCode,
739 : generateErrorArguments(aUncPath),
740 : xEnv,
741 : rtl::OUString( "a file or directory could not be deleted"),
742 0 : xComProc );
743 : }
744 59 : else if( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
745 : errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
746 : errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
747 : errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT ||
748 : errorCode == TASKHANDLING_TRANSFER_DESTFILETYPE ||
749 : errorCode == TASKHANDLING_FILETYPE_FOR_REMOVE ||
750 : errorCode == TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE ||
751 : errorCode == TASKHANDLING_TRANSFER_INVALIDURL )
752 : {
753 59 : rtl::OUString aMsg;
754 59 : switch( minorCode )
755 : {
756 : case FileBase::E_NOENT: // No such file or directory
757 0 : if ( errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCE ||
758 : errorCode == TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT ||
759 : errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCE ||
760 : errorCode == TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT )
761 : {
762 0 : ioErrorCode = IOErrorCode_NOT_EXISTING;
763 0 : aMsg = rtl::OUString( "source file/folder does not exist");
764 0 : break;
765 : }
766 : else
767 : {
768 0 : ioErrorCode = IOErrorCode_GENERAL;
769 0 : aMsg = rtl::OUString( "a general error during transfer command");
770 0 : break;
771 : }
772 : default:
773 59 : ioErrorCode = IOErrorCode_GENERAL;
774 59 : aMsg = rtl::OUString( "a general error during transfer command");
775 59 : break;
776 : }
777 : cancelCommandExecution(
778 : ioErrorCode,
779 : generateErrorArguments(aUncPath),
780 : xEnv,
781 : aMsg,
782 118 : xComProc );
783 : }
784 0 : else if( errorCode == TASKHANDLING_TRANSFER_ACCESSINGROOT )
785 : {
786 0 : ioErrorCode = IOErrorCode_WRITE_PROTECTED;
787 : cancelCommandExecution(
788 : ioErrorCode,
789 : generateErrorArguments(aUncPath),
790 : xEnv,
791 : rtl::OUString( "accessing the root during transfer"),
792 0 : xComProc );
793 : }
794 0 : else if( errorCode == TASKHANDLING_TRANSFER_INVALIDSCHEME )
795 : {
796 0 : Reference<XInterface> xContext(xComProc,UNO_QUERY);
797 :
798 : aAny <<=
799 : InteractiveBadTransferURLException(
800 : rtl::OUString( "bad tranfer url"),
801 0 : xContext);
802 0 : cancelCommandExecution( aAny,xEnv );
803 : }
804 0 : else if( errorCode == TASKHANDLING_OVERWRITE_FOR_MOVE ||
805 : errorCode == TASKHANDLING_OVERWRITE_FOR_COPY ||
806 : errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_MOVE ||
807 : errorCode == TASKHANDLING_NAMECLASHMOVE_FOR_COPY ||
808 : errorCode == TASKHANDLING_KEEPERROR_FOR_MOVE ||
809 : errorCode == TASKHANDLING_KEEPERROR_FOR_COPY ||
810 : errorCode == TASKHANDLING_RENAME_FOR_MOVE ||
811 : errorCode == TASKHANDLING_RENAME_FOR_COPY ||
812 : errorCode == TASKHANDLING_RENAMEMOVE_FOR_MOVE ||
813 : errorCode == TASKHANDLING_RENAMEMOVE_FOR_COPY )
814 : {
815 : rtl::OUString aMsg(
816 0 : "general error during transfer");
817 :
818 0 : switch( minorCode )
819 : {
820 : case FileBase::E_EXIST:
821 0 : ioErrorCode = IOErrorCode_ALREADY_EXISTING;
822 0 : break;
823 : case FileBase::E_INVAL: // the format of the parameters was not valid
824 0 : ioErrorCode = IOErrorCode_INVALID_PARAMETER;
825 0 : break;
826 : case FileBase::E_NOMEM: // not enough memory for allocating structures
827 0 : ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
828 0 : break;
829 : case FileBase::E_ACCES: // Permission denied
830 0 : ioErrorCode = IOErrorCode_ACCESS_DENIED;
831 0 : break;
832 : case FileBase::E_PERM: // Operation not permitted
833 0 : ioErrorCode = IOErrorCode_NOT_SUPPORTED;
834 0 : break;
835 : case FileBase::E_NAMETOOLONG: // File name too long
836 0 : ioErrorCode = IOErrorCode_NAME_TOO_LONG;
837 0 : break;
838 : case FileBase::E_NOENT: // No such file or directory
839 0 : ioErrorCode = IOErrorCode_NOT_EXISTING;
840 0 : aMsg = rtl::OUString( "file/folder does not exist");
841 0 : break;
842 : case FileBase::E_ROFS: // Read-only file system<p>
843 0 : ioErrorCode = IOErrorCode_NOT_EXISTING;
844 0 : break;
845 : default:
846 0 : ioErrorCode = IOErrorCode_GENERAL;
847 0 : break;
848 : }
849 : cancelCommandExecution(
850 : ioErrorCode,
851 : generateErrorArguments(aUncPath),
852 : xEnv,
853 : aMsg,
854 0 : xComProc );
855 : }
856 0 : else if( errorCode == TASKHANDLING_NAMECLASH_FOR_COPY ||
857 : errorCode == TASKHANDLING_NAMECLASH_FOR_MOVE )
858 : {
859 0 : NameClashException excep;
860 0 : excep.Name = getTitle(aUncPath);
861 0 : excep.Classification = InteractionClassification_ERROR;
862 0 : Reference<XInterface> xContext(xComProc,UNO_QUERY);
863 0 : excep.Context = xContext;
864 0 : excep.Message = rtl::OUString( "name clash during copy or move");
865 0 : aAny <<= excep;
866 :
867 0 : cancelCommandExecution(aAny,xEnv);
868 : }
869 0 : else if( errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE ||
870 : errorCode == TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY )
871 : {
872 : Reference<XInterface> xContext(
873 0 : xComProc,UNO_QUERY);
874 0 : UnsupportedNameClashException excep;
875 0 : excep.NameClash = minorCode;
876 0 : excep.Context = xContext;
877 0 : excep.Message = rtl::OUString( "name clash value not supported during copy or move");
878 :
879 0 : aAny <<= excep;
880 0 : cancelCommandExecution(aAny,xEnv);
881 : }
882 : else
883 : {
884 : // case TASKHANDLER_NO_ERROR:
885 0 : return;
886 2151 : }
887 : }
888 :
889 :
890 : } // end namespace fileaccess
891 :
892 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|