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