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>
44#include <osl/diagnose.h>
46#include <rtl/ustring.hxx>
61 OUString
const & rPhysicalUrl)
63 OUString aResourceName;
64 OUString aResourceType;
65 bool bRemovable =
false;
66 bool bResourceName =
false;
67 bool bResourceType =
false;
68 bool bRemoveProperty =
false;
70 if (osl::FileBase::getSystemPathFromFileURL(
73 == osl::FileBase::E_None)
79 osl::DirectoryItem aItem;
80 if (osl::DirectoryItem::get(rPhysicalUrl, aItem) ==
81 osl::FileBase::E_None)
83 osl::FileStatus aStatus( osl_FileStatus_Mask_Type );
84 if (aItem.getFileStatus(aStatus) == osl::FileBase::E_None)
85 switch (aStatus.getFileType())
87 case osl::FileStatus::Directory:
88 aResourceType =
"folder";
92 case osl::FileStatus::Volume:
94 aResourceType =
"volume";
96 osl::VolumeInfo aVolumeInfo(
97 osl_VolumeInfo_Mask_Attributes );
98 if( osl::Directory::getVolumeInfo(
99 rPhysicalUrl,aVolumeInfo ) ==
100 osl::FileBase::E_None )
102 bRemovable = aVolumeInfo.getRemoveableFlag();
103 bRemoveProperty =
true;
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:
119 (bResourceName ? 1 : 0) +
120 (bResourceType ? 1 : 0) +
121 (bRemoveProperty ? 1 : 0) );
125 <<= PropertyValue(
"Uri",
128 PropertyState_DIRECT_VALUE);
131 <<= PropertyValue(
"ResourceName",
134 PropertyState_DIRECT_VALUE);
137 <<= PropertyValue(
"ResourceType",
140 PropertyState_DIRECT_VALUE);
143 <<= PropertyValue(
"Removable",
146 PropertyState_DIRECT_VALUE);
157 std::u16string_view dstUnqPath )
161 size_t srcL = srcUnqPath.size();
162 size_t dstL = dstUnqPath.size();
165 ( srcUnqPath == dstUnqPath )
171 ( dstUnqPath[ srcL ] == slash ) )
177 std::u16string_view aNewPrefix,
178 std::u16string_view aOldPrefix,
179 std::u16string_view old_Name )
181 size_t srcL = aOldPrefix.size();
183 return OUString::Concat(aNewPrefix) + old_Name.substr( srcL );
187 std::u16string_view
getTitle( std::u16string_view aPath )
189 size_t lastIndex = aPath.rfind(
'/' );
190 return aPath.substr( lastIndex + 1 );
196 size_t lastIndex = aFileName.rfind(
'/' );
197 OUString aParent( aFileName.substr( 0,lastIndex ) );
199 if( aParent.endsWith(
":") && aParent.getLength() == 6 )
202 if ( aParent ==
"file://" )
203 aParent =
"file:///";
210 const OUString& strDestPath,
215 osl::DirectoryItem aItem;
216 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
217 return osl::FileBase::E_EXIST;
220 return osl::File::copy( strPath,strDestPath );
225 const OUString& strDestPath,
230 osl::DirectoryItem aItem;
231 if( osl::DirectoryItem::get( strDestPath,aItem ) != osl::FileBase:: E_NOENT )
232 return osl::FileBase::E_EXIST;
235 return osl::File::move( strPath,strDestPath );
242 const OUString& aUncPath,
252 aAny <<= UnsupportedCommandException( OSL_LOG_PREFIX );
263 IllegalArgumentException excep;
264 excep.ArgumentPosition = 0;
269 UnsupportedOpenModeException excep;
270 excep.Mode = sal::static_int_cast< sal_Int16 >(minorCode);
293 case FileBase::E_NAMETOOLONG:
297 case FileBase::E_NXIO:
299 case FileBase::E_NODEV:
303 case FileBase::E_NOTDIR:
306 case FileBase::E_NOENT:
310 case FileBase::E_ROFS:
312 case FileBase::E_ACCES:
313 case FileBase::E_PERM:
317 case FileBase::E_ISDIR:
321 case FileBase::E_NOTREADY:
324 case FileBase::E_MFILE:
326 case FileBase::E_NFILE:
330 case FileBase::E_INVAL:
334 case FileBase::E_NOMEM:
338 case FileBase::E_BUSY:
342 case FileBase::E_AGAIN:
346 case FileBase::E_NOLCK:
349 case FileBase::E_NOSYS:
352 case FileBase::E_FAULT:
353 case FileBase::E_LOOP:
354 case FileBase::E_NOSPC:
355 case FileBase::E_INTR:
357 case FileBase::E_MULTIHOP:
358 case FileBase::E_NOLINK:
366 generateErrorArguments(aUncPath),
368 "an error occurred during file opening",
376 case FileBase::E_INVAL:
380 case FileBase::E_NOENT:
384 case FileBase::E_NOTDIR:
388 case FileBase::E_NOMEM:
392 case FileBase::E_ROFS:
394 case FileBase::E_ACCES:
397 case FileBase::E_NOTREADY:
400 case FileBase::E_MFILE:
402 case FileBase::E_NFILE:
406 case FileBase::E_NAMETOOLONG:
410 case FileBase::E_LOOP:
419 generateErrorArguments(aUncPath),
421 "an error occurred during opening a directory",
434 generateErrorArguments(aUncPath),
436 "an error occurred writing or reading from a file",
444 generateErrorArguments(aUncPath),
454 case FileBase::E_INVAL:
458 case FileBase::E_FBIG:
462 case FileBase::E_NOSPC:
466 case FileBase::E_NXIO:
470 case FileBase::E_NOLINK:
472 case FileBase::E_ISDIR:
476 case FileBase::E_AGAIN:
480 case FileBase::E_TIMEDOUT:
483 case FileBase::E_NOLCK:
487 case FileBase::E_BADF:
488 case FileBase::E_FAULT:
489 case FileBase::E_INTR:
496 generateErrorArguments(aUncPath),
498 "an error occurred during opening a file",
504 static constexpr OUStringLiteral sTitle =
u"Title";
505 static constexpr OUStringLiteral sContentType =
u"ContentType";
508 : OUString(sContentType) };
510 aAny <<= MissingPropertiesException(
511 "a property is missing, necessary to create a content",
520 case FileBase::E_INVAL:
522 case FileBase::E_OVERFLOW:
533 generateErrorArguments(aUncPath),
535 "there were problems with the filesize",
541 MissingInputStreamException(
542 "the inputstream is missing, necessary to create a content",
549 NameClashException excep;
551 excep.Classification = InteractionClassification_ERROR;
553 excep.Message =
"file exists and overwrite forbidden";
558 InteractiveAugmentedIOException excep;
559 excep.Code = IOErrorCode_INVALID_CHARACTER;
561 prop.Name =
"ResourceName";
563 OUString aClashingName(
566 rtl_UriDecodeWithCharset,
567 RTL_TEXTENCODING_UTF8));
568 prop.Value <<= aClashingName;
569 excep.Arguments = {
Any(prop) };
570 excep.Classification = InteractionClassification_ERROR;
572 excep.Message =
"the name contained invalid characters";
586 NameClashException excep;
588 excep.Classification = InteractionClassification_ERROR;
589 excep.Context = xComProc;
590 excep.Message =
"folder exists and overwrite forbidden";
607 case FileBase::E_ACCES:
610 case FileBase::E_ROFS:
613 case FileBase::E_NAMETOOLONG:
625 "a folder could not be created",
634 case FileBase::E_INVAL:
637 case FileBase::E_NOMEM:
640 case FileBase::E_ROFS:
641 case FileBase::E_ACCES:
644 case FileBase::E_MFILE:
645 case FileBase::E_NFILE:
648 case FileBase::E_NOLINK:
649 case FileBase::E_NOENT:
652 case FileBase::E_NAMETOOLONG:
655 case FileBase::E_NOTDIR:
658 case FileBase::E_LOOP:
660 case FileBase::E_MULTIHOP:
661 case FileBase::E_FAULT:
662 case FileBase::E_INTR:
663 case FileBase::E_NOSYS:
664 case FileBase::E_NOSPC:
665 case FileBase::E_NXIO:
666 case FileBase::E_OVERFLOW:
667 case FileBase::E_BADF:
674 generateErrorArguments(aUncPath),
676 "a file status object could not be filled",
684 case FileBase::E_INVAL:
687 case FileBase::E_NOMEM:
690 case FileBase::E_ACCES:
693 case FileBase::E_PERM:
696 case FileBase::E_NAMETOOLONG:
699 case FileBase::E_NOLINK:
700 case FileBase::E_NOENT:
703 case FileBase::E_ISDIR:
704 case FileBase::E_ROFS:
707 case FileBase::E_BUSY:
710 case FileBase::E_FAULT:
711 case FileBase::E_LOOP:
713 case FileBase::E_INTR:
714 case FileBase::E_MULTIHOP:
721 generateErrorArguments(aUncPath),
723 "a file or directory could not be deleted",
738 case FileBase::E_NOENT:
745 aMsg =
"source file/folder does not exist";
751 aMsg =
"a general error during transfer command";
756 aMsg =
"a general error during transfer command";
761 generateErrorArguments(aUncPath),
771 generateErrorArguments(aUncPath),
773 "accessing the root during transfer",
778 aAny <<= InteractiveBadTransferURLException(
795 "general error during transfer");
799 case FileBase::E_EXIST:
802 case FileBase::E_INVAL:
805 case FileBase::E_NOMEM:
808 case FileBase::E_ACCES:
811 case FileBase::E_PERM:
814 case FileBase::E_NAMETOOLONG:
817 case FileBase::E_NOENT:
819 aMsg =
"file/folder does not exist";
821 case FileBase::E_ROFS:
830 generateErrorArguments(aUncPath),
838 NameClashException excep;
840 excep.Classification = InteractionClassification_ERROR;
842 excep.Message =
"name clash during copy or move";
849 UnsupportedNameClashException excep;
850 excep.NameClash = minorCode;
852 excep.Message =
"name clash value not supported during copy or move";
#define TASKHANDLING_FILETYPE_FOR_REMOVE
#define TASKHANDLING_FOLDER_EXISTS_MKDIR
#define TASKHANDLING_CREATEDIRECTORY_MKDIR
#define TASKHANDLING_TRANSFER_INVALIDURL
#define TASKHANDLING_VALIDFILESTATUSWHILE_FOR_REMOVE
#define TASKHANDLING_TRANSFER_BY_COPY_SOURCE
#define TASKHANDLING_IOEXCEPTION_FOR_WRITE
#define TASKHANDLING_FILEIOERROR_FOR_WRITE
#define TASKHANDLING_TRANSFER_BY_MOVE_SOURCE
#define TASKHANDLING_UNSUPPORTED_OPEN_MODE
#define TASKHANDLING_OPEN_FOR_DIRECTORYLISTING
#define TASKHANDLING_OPEN_FILE_FOR_PAGING
#define TASKHANDLING_DIRECTORYEXHAUSTED_FOR_REMOVE
#define TASKHANDLING_NAMECLASH_FOR_COPY
#define TASKHANDLING_INPUTSTREAM_FOR_WRITE
#define TASKHANDLING_DELETEDIRECTORY_FOR_REMOVE
#define TASKHANDLING_KEEPERROR_FOR_MOVE
#define TASKHANDLING_WRONG_OPEN_ARGUMENT
#define TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT
#define TASKHANDLING_TRANSFER_BY_COPY_SOURCESTAT
#define TASKHANDLING_READING_FILE_FOR_PAGING
#define TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT
#define TASKHANDLING_NAMECLASHMOVE_FOR_COPY
#define TASKHANDLING_VALIDFILESTATUS_FOR_REMOVE
#define TASKHANDLING_NAMECLASHMOVE_FOR_MOVE
#define TASKHANDLING_WRONG_DELETE_ARGUMENT
#define TASKHANDLING_RENAMEMOVE_FOR_MOVE
#define TASKHANDLING_OVERWRITE_FOR_COPY
#define TASKHANDLING_OPEN_FOR_STREAM
#define TASKHANDLING_DELETEFILE_FOR_REMOVE
#define TASKHANDLING_WRONG_TRANSFER_ARGUMENT
#define TASKHANDLING_NOSUCHFILEORDIR_FOR_REMOVE
#define TASKHANDLING_RENAME_FOR_MOVE
#define TASKHANDLING_NONAMESET_INSERT_COMMAND
#define TASKHANDLING_WRONG_INSERT_ARGUMENT
#define TASKHANDLING_RENAME_FOR_COPY
#define TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND
#define TASKHANDLER_UNSUPPORTED_COMMAND
#define TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND
#define TASKHANDLING_TRANSFER_BY_MOVE_SOURCESTAT
#define TASKHANDLING_ENSUREDIR_FOR_WRITE
#define TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND
#define TASKHANDLING_RENAMEMOVE_FOR_COPY
#define TASKHANDLING_TRANSFER_INVALIDSCHEME
#define TASKHANDLING_NOREPLACE_FOR_WRITE
#define TASKHANDLING_NOTCONNECTED_FOR_WRITE
#define TASKHANDLING_OVERWRITE_FOR_MOVE
#define TASKHANDLING_NO_OPEN_FILE_FOR_OVERWRITE
#define TASKHANDLING_KEEPERROR_FOR_COPY
#define TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND
#define TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_WRITE
#define TASKHANDLING_OPEN_FOR_INPUTSTREAM
#define TASKHANDLING_INVALID_NAME_MKDIR
#define TASKHANDLING_FILEIOERROR_FOR_NO_SPACE
#define TASKHANDLING_TRANSFER_DESTFILETYPE
#define TASKHANDLING_NAMECLASH_FOR_MOVE
#define TASKHANDLING_TRANSFER_ACCESSINGROOT
#define TASKHANDLING_BUFFERSIZEEXCEEDED_FOR_PAGING
#define TASKHANDLING_NOTCONNECTED_FOR_PAGING
#define TASKHANDLING_OPENDIRECTORY_FOR_REMOVE
#define TASKHANDLING_IOEXCEPTION_FOR_PAGING
#define TASKHANDLING_NAMECLASHSUPPORT_FOR_MOVE
#define TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT
#define TASKHANDLING_NO_OPEN_FILE_FOR_WRITE
#define TASKHANDLING_FILESIZE_FOR_WRITE
#define TASKHANDLING_NAMECLASHSUPPORT_FOR_COPY
Sequence< PropertyValue > aArguments
Sequence< sal_Int8 > aSeq
OUString getParentName(std::u16string_view aFileName)
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...
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...
void throw_handler(sal_Int32 errorCode, sal_Int32 minorCode, const Reference< XCommandEnvironment > &xEnv, const OUString &aUncPath, BaseContent *pContent, bool isHandled)
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
bool isChild(std::u16string_view srcUnqPath, std::u16string_view dstUnqPath)
std::u16string_view getTitle(std::u16string_view aPath)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
UCBHELPER_DLLPUBLIC void cancelCommandExecution(const css::uno::Any &rException, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)