summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-09-07 17:11:48 +0300
committerStephan Bergmann <sbergman@redhat.com>2018-09-27 23:20:32 +0200
commit4f28521bf96d4a5fedad3c85171baba412abbb0e (patch)
treea5e16b6ef56288ca3e130306e35304cd782374b4 /include
parent3ab472e718ea590a5c0dba572cf91e79ab916562 (diff)
tdf#119238: keep replaced file's identity when renaming docfile
Regression from 2157a3536f97ff5ae7c82611a801fef7e3708983 sfx2 store: try rename before copying Rename is cheaper then copying the content over manually, so try that first. On Windows, we need to keep the file's dentity, including metadata (e.g., creation time, which is kept in FS). WinAPI has ReplaceFileW specifically for this, and it keeps ACLs of the original file, and otherwise makes the changed file not a separate entry, but updated old file from system's PoV. Eventually, we could try to restructure creating backup copies (e.g., for documents when configured so) to take advantage of this function being able to do that. Change-Id: I6001a2a3af5e10bc010f5ef129f4bb6f83ee1581 Reviewed-on: https://gerrit.libreoffice.org/60163 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins (cherry picked from commit c9343988204ee3e9889f3cc833adbbaca83e53e6) Reviewed-on: https://gerrit.libreoffice.org/61041
Diffstat (limited to 'include')
-rw-r--r--include/osl/file.h31
-rw-r--r--include/osl/file.hxx33
2 files changed, 64 insertions, 0 deletions
diff --git a/include/osl/file.h b/include/osl/file.h
index 038631a86618..884eb71998e6 100644
--- a/include/osl/file.h
+++ b/include/osl/file.h
@@ -1634,6 +1634,37 @@ SAL_DLLPUBLIC oslFileError SAL_CALL osl_createTempFile(
oslFileHandle* pHandle,
rtl_uString** ppustrTempFileURL);
+/** Move a file to a new destination or rename it, taking old file's identity (if exists).
+
+ Moves or renames a file, replacing an existing file if exist. If the old file existed,
+ moved file's metadata, e.g. creation time (on FSes which keep files' creation time) or
+ ACLs, are set to old one's (to keep the old file's identity) - currently this is only
+ implemented on Windows; on other platforms, this is equivalent to osl_moveFile.
+
+ @param[in] pustrSourceFileURL
+ Full qualified URL of the source file.
+
+ @param[in] pustrDestFileURL
+ Full qualified URL of the destination file.
+
+ @retval osl_File_E_None on success
+ @retval osl_File_E_INVAL the format of the parameters was not valid
+ @retval osl_File_E_NOMEM not enough memory for allocating structures
+ @retval osl_File_E_ACCES permission denied
+ @retval osl_File_E_PERM operation not permitted
+ @retval osl_File_E_NAMETOOLONG file name too long
+ @retval osl_File_E_NOENT no such file
+ @retval osl_File_E_ROFS read-only file system
+ @retval osl_File_E_BUSY if the implementation internally requires resources that are
+ (temporarily) unavailable
+
+ @see osl_moveFile()
+
+ @since LibreOffice 6.1
+*/
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_replaceFile(rtl_uString* pustrSourceFileURL,
+ rtl_uString* pustrDestFileURL);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/osl/file.hxx b/include/osl/file.hxx
index 6d1a755ac422..22da132ef60c 100644
--- a/include/osl/file.hxx
+++ b/include/osl/file.hxx
@@ -1300,6 +1300,39 @@ public:
return static_cast< RC >( osl_moveFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
}
+ /** Move a file to a new destination or rename it, taking old file's identity (if exists).
+
+ Moves or renames a file, replacing an existing file if exist. If the old file existed,
+ moved file's metadata, e.g. creation time (on FSes which keep files' creation time) or
+ ACLs, are set to old one's (to keep the old file's identity) - currently this is only
+ implemented on Windows; on other platforms, this is equivalent to osl_moveFile.
+
+ @param[in] ustrSourceFileURL
+ Full qualified URL of the source file.
+
+ @param[in] ustrDestFileURL
+ Full qualified URL of the destination file.
+
+ @retval E_None on success
+ @retval E_INVAL the format of the parameters was not valid
+ @retval E_NOMEM not enough memory for allocating structures
+ @retval E_ACCES permission denied
+ @retval E_PERM operation not permitted
+ @retval E_NAMETOOLONG file name too long
+ @retval E_NOENT no such file
+ @retval E_ROFS read-only file system
+ @retval E_BUSY device or resource busy
+
+ @see move()
+
+ @since LibreOffice 6.1
+ */
+ static RC replace(const ::rtl::OUString& ustrSourceFileURL,
+ const ::rtl::OUString& ustrDestFileURL)
+ {
+ return static_cast<RC>(osl_replaceFile(ustrSourceFileURL.pData, ustrDestFileURL.pData));
+ }
+
/** Remove a regular file.
@param[in] ustrFileURL