diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-09-09 23:13:12 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-10-01 08:18:06 +0200 |
commit | cb14e82a823f313e3e1bedc83c60a5d575b1c89e (patch) | |
tree | 5a6e98dc67705d0e9b5dff913ea7f823d97fb41c /sal/osl/unx | |
parent | tdf#76324 speedup copy operation with lots of comments in calc (diff) | |
download | core-cb14e82a823f313e3e1bedc83c60a5d575b1c89e.tar.gz core-cb14e82a823f313e3e1bedc83c60a5d575b1c89e.zip |
tdf#127069 sal: preserve gid of files in the unx osl_replaceFile()
The w32 implementation preserves all attributes of the destination
file, the unx one preserved none of them.
Bring the unx osl_replaceFile() closer to the w32 by preserving the gid
of the destination file as a start.
[ No testcase, we support building on systems where the user is part of
a single group only, and it's not possible to verify the effect of this
change in such environments. ]
(cherry picked from commit eedf523c123a82bf3cbc5f389783e22d75b2e2c5)
Change-Id: I722d4802df34caf71a9dc0db1a3df8b76acb9de6
Reviewed-on: https://gerrit.libreoffice.org/79037
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/osl/unx')
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index 31641593e781..74d936ae33c8 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -620,7 +620,38 @@ oslFileError SAL_CALL osl_moveFile( rtl_uString* ustrFileURL, rtl_uString* ustrD oslFileError SAL_CALL osl_replaceFile(rtl_uString* ustrFileURL, rtl_uString* ustrDestURL) { - return osl_moveFile(ustrFileURL, ustrDestURL); + int nGid = -1; + char destPath[PATH_MAX]; + oslFileError eRet = FileURLToPath(destPath, PATH_MAX, ustrDestURL); + if (eRet == osl_File_E_None) + { + struct stat aFileStat; + int nRet = stat(destPath, &aFileStat); + if (nRet == -1) + { + nRet = errno; + SAL_INFO("sal.file", "stat(" << destPath << "): " << UnixErrnoString(nRet)); + } + else + { + nGid = aFileStat.st_gid; + } + } + + eRet = osl_moveFile(ustrFileURL, ustrDestURL); + + if (eRet == osl_File_E_None && nGid != -1) + { + int nRet = chown(destPath, -1, nGid); + if (nRet == -1) + { + nRet = errno; + SAL_INFO("sal.file", + "chown(" << destPath << "-1, " << nGid << "): " << UnixErrnoString(nRet)); + } + } + + return eRet; } oslFileError SAL_CALL osl_copyFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) |