22 #include <string_view>
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>
60 OUString
const & rPhysicalUrl)
62 OUString aResourceName;
63 OUString aResourceType;
64 bool bRemovable =
false;
65 bool bResourceName =
false;
66 bool bResourceType =
false;
67 bool bRemoveProperty =
false;
69 if (osl::FileBase::getSystemPathFromFileURL(
72 == osl::FileBase::E_None)
78 osl::DirectoryItem aItem;
79 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
80 osl::FileBase::E_None)
82 osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
83 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
84 switch (aStatus.getFileType())
86 case osl::FileStatus::Directory:
87 aResourceType =
"folder";
91 case osl::FileStatus::Volume:
93 aResourceType =
"volume";
95 osl::VolumeInfo aVolumeInfo(
96 osl_VolumeInfo_Mask_Attributes );
97 if( osl::Directory::getVolumeInfo(
98 rPhysicalUrl,aVolumeInfo ) ==
99 osl::FileBase::E_None )
101 bRemovable = aVolumeInfo.getRemoveableFlag();
102 bRemoveProperty =
true;
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:
118 (bResourceName ? 1 : 0) +
119 (bResourceType ? 1 : 0) +
120 (bRemoveProperty ? 1 : 0) );
124 <<= PropertyValue(
"Uri",
127 PropertyState_DIRECT_VALUE);
130 <<= PropertyValue(
"ResourceName",
133 PropertyState_DIRECT_VALUE);
136 <<= PropertyValue(
"ResourceType",
139 PropertyState_DIRECT_VALUE);
142 <<= PropertyValue(
"Removable",
145 PropertyState_DIRECT_VALUE);
156 const OUString& dstUnqPath )
160 sal_Int32 srcL = srcUnqPath.getLength();
161 sal_Int32 dstL = dstUnqPath.getLength();
164 ( srcUnqPath == dstUnqPath )
168 dstUnqPath.startsWith(srcUnqPath)
170 ( dstUnqPath[ srcL ] == slash ) )
176 std::u16string_view aNewPrefix,
177 const OUString& aOldPrefix,
178 std::u16string_view old_Name )
180 sal_Int32 srcL = aOldPrefix.getLength();
182 return OUString::Concat(aNewPrefix) + old_Name.substr( srcL );
186 std::u16string_view
getTitle( std::u16string_view aPath )
188 size_t lastIndex = aPath.rfind(
'/' );
189 return aPath.substr( lastIndex + 1 );
195 size_t lastIndex = aFileName.rfind(
'/' );
196 OUString aParent( aFileName.substr( 0,lastIndex ) );
198 if( aParent.endsWith(
":") && aParent.getLength() == 6 )
201 if ( aParent ==
"file://" )
202 aParent =
"file:///";
209 const OUString& strDestPath,
214 osl::DirectoryItem aItem;
215 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
216 return osl::FileBase::E_EXIST;
219 return osl::File::copy( strPath,strDestPath );
224 const OUString& strDestPath,
229 osl::DirectoryItem aItem;
230 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
231 return osl::FileBase::E_EXIST;
234 return osl::File::move( strPath,strDestPath );
241 const OUString& aUncPath,
251 aAny <<= UnsupportedCommandException( OSL_LOG_PREFIX );
262 IllegalArgumentException excep;
263 excep.ArgumentPosition = 0;
268 UnsupportedOpenModeException excep;
269 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
292 case FileBase::E_NAMETOOLONG:
294 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
296 case FileBase::E_NXIO:
298 case FileBase::E_NODEV:
300 ioErrorCode = IOErrorCode_INVALID_DEVICE;
302 case FileBase::E_NOTDIR:
303 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
305 case FileBase::E_NOENT:
307 ioErrorCode = IOErrorCode_NOT_EXISTING;
309 case FileBase::E_ROFS:
311 case FileBase::E_ACCES:
312 case FileBase::E_PERM:
314 ioErrorCode = IOErrorCode_ACCESS_DENIED;
316 case FileBase::E_ISDIR:
318 ioErrorCode = IOErrorCode_NO_FILE;
320 case FileBase::E_NOTREADY:
321 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
323 case FileBase::E_MFILE:
325 case FileBase::E_NFILE:
327 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
329 case FileBase::E_INVAL:
331 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
333 case FileBase::E_NOMEM:
335 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
337 case FileBase::E_BUSY:
339 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
341 case FileBase::E_AGAIN:
343 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
345 case FileBase::E_NOLCK:
346 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
348 case FileBase::E_NOSYS:
349 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
351 case FileBase::E_FAULT:
352 case FileBase::E_LOOP:
353 case FileBase::E_NOSPC:
354 case FileBase::E_INTR:
356 case FileBase::E_MULTIHOP:
357 case FileBase::E_NOLINK:
359 ioErrorCode = IOErrorCode_GENERAL;
365 generateErrorArguments(aUncPath),
367 "an error occurred during file opening",
375 case FileBase::E_INVAL:
377 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
379 case FileBase::E_NOENT:
381 ioErrorCode = IOErrorCode_NOT_EXISTING;
383 case FileBase::E_NOTDIR:
385 ioErrorCode = IOErrorCode_NO_DIRECTORY;
387 case FileBase::E_NOMEM:
389 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
391 case FileBase::E_ROFS:
393 case FileBase::E_ACCES:
394 ioErrorCode = IOErrorCode_ACCESS_DENIED;
396 case FileBase::E_NOTREADY:
397 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
399 case FileBase::E_MFILE:
401 case FileBase::E_NFILE:
403 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
405 case FileBase::E_NAMETOOLONG:
407 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
409 case FileBase::E_LOOP:
412 ioErrorCode = IOErrorCode_GENERAL;
418 generateErrorArguments(aUncPath),
420 "an error occurred during opening a directory",
430 ioErrorCode = IOErrorCode_UNKNOWN;
433 generateErrorArguments(aUncPath),
435 "an error occurred writing or reading from a file",
440 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
443 generateErrorArguments(aUncPath),
453 case FileBase::E_INVAL:
455 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
457 case FileBase::E_FBIG:
459 ioErrorCode = IOErrorCode_CANT_WRITE;
461 case FileBase::E_NOSPC:
463 ioErrorCode = IOErrorCode_OUT_OF_DISK_SPACE;
465 case FileBase::E_NXIO:
467 ioErrorCode = IOErrorCode_INVALID_DEVICE;
469 case FileBase::E_NOLINK:
471 case FileBase::E_ISDIR:
473 ioErrorCode = IOErrorCode_NO_FILE;
475 case FileBase::E_AGAIN:
477 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
479 case FileBase::E_TIMEDOUT:
480 ioErrorCode = IOErrorCode_DEVICE_NOT_READY;
482 case FileBase::E_NOLCK:
483 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
486 case FileBase::E_BADF:
487 case FileBase::E_FAULT:
488 case FileBase::E_INTR:
490 ioErrorCode = IOErrorCode_GENERAL;
495 generateErrorArguments(aUncPath),
497 "an error occurred during opening a file",
503 static constexpr OUStringLiteral sTitle =
u"Title";
504 static constexpr OUStringLiteral sContentType =
u"ContentType";
507 : OUString(sContentType) };
509 aAny <<= MissingPropertiesException(
510 "a property is missing, necessary to create a content",
519 case FileBase::E_INVAL:
521 case FileBase::E_OVERFLOW:
524 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
527 ioErrorCode = IOErrorCode_GENERAL;
532 generateErrorArguments(aUncPath),
534 "there were problems with the filesize",
540 MissingInputStreamException(
541 "the inputstream is missing, necessary to create a content",
548 NameClashException excep;
550 excep.Classification = InteractionClassification_ERROR;
552 excep.Message =
"file exists and overwrite forbidden";
557 InteractiveAugmentedIOException excep;
558 excep.Code = IOErrorCode_INVALID_CHARACTER;
560 prop.Name =
"ResourceName";
562 OUString aClashingName(
565 rtl_UriDecodeWithCharset,
566 RTL_TEXTENCODING_UTF8));
567 prop.Value <<= aClashingName;
568 excep.Arguments = {
Any(prop) };
569 excep.Classification = InteractionClassification_ERROR;
571 excep.Message =
"the name contained invalid characters";
585 NameClashException excep;
587 excep.Classification = InteractionClassification_ERROR;
588 excep.Context = xComProc;
589 excep.Message =
"folder exists and overwrite forbidden";
606 case FileBase::E_ACCES:
607 ioErrorCode = IOErrorCode_ACCESS_DENIED;
609 case FileBase::E_ROFS:
610 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
612 case FileBase::E_NAMETOOLONG:
613 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
616 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
624 "a folder could not be created",
633 case FileBase::E_INVAL:
634 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
636 case FileBase::E_NOMEM:
637 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
639 case FileBase::E_ROFS:
640 case FileBase::E_ACCES:
641 ioErrorCode = IOErrorCode_ACCESS_DENIED;
643 case FileBase::E_MFILE:
644 case FileBase::E_NFILE:
645 ioErrorCode = IOErrorCode_OUT_OF_FILE_HANDLES;
647 case FileBase::E_NOLINK:
648 case FileBase::E_NOENT:
649 ioErrorCode = IOErrorCode_NOT_EXISTING;
651 case FileBase::E_NAMETOOLONG:
652 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
654 case FileBase::E_NOTDIR:
655 ioErrorCode = IOErrorCode_NOT_EXISTING_PATH;
657 case FileBase::E_LOOP:
659 case FileBase::E_MULTIHOP:
660 case FileBase::E_FAULT:
661 case FileBase::E_INTR:
662 case FileBase::E_NOSYS:
663 case FileBase::E_NOSPC:
664 case FileBase::E_NXIO:
665 case FileBase::E_OVERFLOW:
666 case FileBase::E_BADF:
668 ioErrorCode = IOErrorCode_GENERAL;
673 generateErrorArguments(aUncPath),
675 "a file status object could not be filled",
683 case FileBase::E_INVAL:
684 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
686 case FileBase::E_NOMEM:
687 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
689 case FileBase::E_ACCES:
690 ioErrorCode = IOErrorCode_ACCESS_DENIED;
692 case FileBase::E_PERM:
693 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
695 case FileBase::E_NAMETOOLONG:
696 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
698 case FileBase::E_NOLINK:
699 case FileBase::E_NOENT:
700 ioErrorCode = IOErrorCode_NOT_EXISTING;
702 case FileBase::E_ISDIR:
703 case FileBase::E_ROFS:
704 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
706 case FileBase::E_BUSY:
707 ioErrorCode = IOErrorCode_LOCKING_VIOLATION;
709 case FileBase::E_FAULT:
710 case FileBase::E_LOOP:
712 case FileBase::E_INTR:
713 case FileBase::E_MULTIHOP:
715 ioErrorCode = IOErrorCode_GENERAL;
720 generateErrorArguments(aUncPath),
722 "a file or directory could not be deleted",
737 case FileBase::E_NOENT:
743 ioErrorCode = IOErrorCode_NOT_EXISTING;
744 aMsg =
"source file/folder does not exist";
749 ioErrorCode = IOErrorCode_GENERAL;
750 aMsg =
"a general error during transfer command";
754 ioErrorCode = IOErrorCode_GENERAL;
755 aMsg =
"a general error during transfer command";
760 generateErrorArguments(aUncPath),
767 ioErrorCode = IOErrorCode_WRITE_PROTECTED;
770 generateErrorArguments(aUncPath),
772 "accessing the root during transfer",
777 aAny <<= InteractiveBadTransferURLException(
794 "general error during transfer");
798 case FileBase::E_EXIST:
799 ioErrorCode = IOErrorCode_ALREADY_EXISTING;
801 case FileBase::E_INVAL:
802 ioErrorCode = IOErrorCode_INVALID_PARAMETER;
804 case FileBase::E_NOMEM:
805 ioErrorCode = IOErrorCode_OUT_OF_MEMORY;
807 case FileBase::E_ACCES:
808 ioErrorCode = IOErrorCode_ACCESS_DENIED;
810 case FileBase::E_PERM:
811 ioErrorCode = IOErrorCode_NOT_SUPPORTED;
813 case FileBase::E_NAMETOOLONG:
814 ioErrorCode = IOErrorCode_NAME_TOO_LONG;
816 case FileBase::E_NOENT:
817 ioErrorCode = IOErrorCode_NOT_EXISTING;
818 aMsg =
"file/folder does not exist";
820 case FileBase::E_ROFS:
821 ioErrorCode = IOErrorCode_NOT_EXISTING;
824 ioErrorCode = IOErrorCode_GENERAL;
829 generateErrorArguments(aUncPath),
837 NameClashException excep;
839 excep.Classification = InteractionClassification_ERROR;
841 excep.Message =
"name clash during copy or move";
848 UnsupportedNameClashException excep;
849 excep.NameClash = minorCode;
851 excep.Message =
"name clash value not supported during copy or move";
#define TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT
#define TASKHANDLING_WRONG_TRANSFER_ARGUMENT
void throw_handler(sal_Int32 errorCode, sal_Int32 minorCode, const Reference< XCommandEnvironment > &xEnv, const OUString &aUncPath, BaseContent *pContent, bool isHandled)
#define TASKHANDLING_WRONG_DELETE_ARGUMENT
#define TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE
#define TASKHANDLING_ENSUREDIR_FOR_WRITE
#define TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT
#define TASKHANDLING_TRANSFER_BY_MOVE_SOURCE
#define TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE
#define TASKHANDLING_RENAME_FOR_MOVE
#define TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE
#define TASKHANDLING_OPEN_FILE_FOR_PAGING
#define TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT
#define TASKHANDLING_UNSUPPORTED_OPEN_MODE
#define TASKHANDLING_NAMECLASHMOVE_FOR_MOVE
#define TASKHANDLING_OPENDIRECTORY_FOR_REMOVE
#define TASKHANDLING_RENAMEMOVE_FOR_MOVE
#define TASKHANDLING_IOEXCEPTION_FOR_WRITE
#define TASKHANDLING_INPUTSTREAM_FOR_WRITE
#define TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE
#define TASKHANDLING_NOREPLACE_FOR_WRITE
OUString newName(std::u16string_view aNewPrefix, const OUString &aOldPrefix, std::u16string_view old_Name)
#define TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE
#define TASKHANDLING_NAMECLASHMOVE_FOR_COPY
#define TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND
#define TASKHANDLING_OVERWRITE_FOR_COPY
#define TASKHANDLING_TRANSFER_INVALIDURL
#define TASKHANDLING_FOLDER_EXISTS_MKDIR
#define TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND
#define TASKHANDLER_UNSUPPORTED_COMMAND
bool isChild(const OUString &srcUnqPath, const OUString &dstUnqPath)
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...
#define TASKHANDLING_RENAME_FOR_COPY
Sequence< PropertyValue > aArguments
#define TASKHANDLING_TRANSFER_DESTFILETYPE
#define TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE
#define TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE
#define TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING
#define TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND
#define TASKHANDLING_OPEN_FOR_DIRECTORYLISTING
#define TASKHANDLING_READING_FILE_FOR_PAGING
#define TASKHANDLING_TRANSFER_INVALIDSCHEME
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
#define TASKHANDLING_FILEIOERROR_FOR_WRITE
#define TASKHANDLING_OPEN_FOR_INPUTSTREAM
#define TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT
#define TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT
#define TASKHANDLING_FILESIZE_FOR_WRITE
#define TASKHANDLING_FILEIOERROR_FOR_NO_SPACE
#define TASKHANDLING_RENAMEMOVE_FOR_COPY
#define TASKHANDLING_DELETEFILE_FOR_REMOVE
OUString getParentName(std::u16string_view aFileName)
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...
#define TASKHANDLING_INVALID_NAME_MKDIR
#define TASKHANDLING_NO_OPEN_FILE_FOR_WRITE
#define TASKHANDLING_TRANSFER_ACCESSINGROOT
std::u16string_view getTitle(std::u16string_view aPath)
#define TASKHANDLING_NAMECLASH_FOR_COPY
#define TASKHANDLING_FILETYPE_FOR_REMOVE
#define TASKHANDLING_TRANSFER_BY_COPY_SOURCE
#define TASKHANDLING_WRONG_OPEN_ARGUMENT
#define TASKHANDLING_NOTCONNECTED_FOR_WRITE
#define TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE
#define TASKHANDLING_IOEXCEPTION_FOR_PAGING
Sequence< sal_Int8 > aSeq
#define TASKHANDLING_NAMECLASH_FOR_MOVE
#define TASKHANDLING_NOTCONNECTED_FOR_PAGING
#define TASKHANDLING_KEEPERROR_FOR_MOVE
#define TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY
#define TASKHANDLING_OVERWRITE_FOR_MOVE
#define TASKHANDLING_CREATEDIRECTORY_MKDIR
#define TASKHANDLING_WRONG_INSERT_ARGUMENT
#define TASKHANDLING_NONAMESET_INSERT_COMMAND
#define TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND
#define TASKHANDLING_KEEPERROR_FOR_COPY
#define TASKHANDLING_OPEN_FOR_STREAM