summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-03-26 10:40:52 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-03-26 17:40:28 +0200
commit546ed01e62c9a36a675c7390371aaec7f1647a33 (patch)
tree2d0c9f0e49b3512b0a3431d501f87a820fa83cb6 /sfx2/source
parent5e18136a01208f5df7c5f554bbcdab2ef661e136 (diff)
sfx2 store: avoid rename() for files with >1 hard link count
Rename would break the hard link; in practice e.g. Online's 'make run' debug feature depends on not breaking hardlinks. Change-Id: Id3ac19493b6b473274b7ed53a4ca06fc34bc1668 Reviewed-on: https://gerrit.libreoffice.org/51858 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/doc/docfile.cxx28
1 files changed, 27 insertions, 1 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 63ce058f0a47..d3f78d2d6078 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -19,6 +19,10 @@
#include <config_features.h>
+#ifdef UNX
+#include <sys/stat.h>
+#endif
+
#include <sfx2/docfile.hxx>
#include <sfx2/signaturestate.hxx>
@@ -190,6 +194,28 @@ sal_uInt64 GetDefaultFileAttributes(const OUString& rURL)
return nRet;
}
+/// Determines if rURL is a non-hard-linked file:// URL.
+bool IsNotHardLinkedFile(const OUString& rURL)
+{
+ if (!comphelper::isFileUrl(rURL))
+ return false;
+
+#ifdef UNX
+ OUString rPath;
+ if (osl::FileBase::getSystemPathFromFileURL(rURL, rPath) != osl::FileBase::E_None)
+ return false;
+
+ struct stat buf;
+ if (stat(rPath.toUtf8().getStr(), &buf) != 0)
+ return false;
+
+ if (buf.st_nlink > 1)
+ return false;
+#endif
+
+ return true;
+}
+
} // anonymous namespace
class SfxMedium_Impl
@@ -1812,7 +1838,7 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource,
OUString aDestMainURL = aDest.GetMainURL(INetURLObject::DecodeMechanism::NONE);
sal_uInt64 nAttributes = GetDefaultFileAttributes(aDestMainURL);
- if (comphelper::isFileUrl(aDestMainURL) && osl::File::move(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
+ if (IsNotHardLinkedFile(aDestMainURL) && osl::File::move(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
{
if (nAttributes)
// Adjust attributes, source might be created with