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