diff options
author | hjk <[email protected]> | 2021-06-09 15:40:06 +0200 |
---|---|---|
committer | hjk <[email protected]> | 2021-06-14 11:20:15 +0000 |
commit | 31dd9c87f83c88e8cfb5941654e7aa7e590f2142 (patch) | |
tree | 402f0c30ca0d1163a0239dc95ffce263101e65ab /src/libs/utils/fileutils.cpp | |
parent | a5b16f8137a8b14e849d08a7f90d323301773942 (diff) |
Utils: Make FileUtils::copyIfDifferent work also with remote paths
Also really check contents if file dates are equal.
Change-Id: I39fca67b3616e931f1ed11d002fccaa232a0d74d
Reviewed-by: David Schulz <[email protected]>
Diffstat (limited to 'src/libs/utils/fileutils.cpp')
-rw-r--r-- | src/libs/utils/fileutils.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 92c3ac819f7..1c4bb869166 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -168,25 +168,30 @@ bool FileUtils::copyRecursively(const FilePath &srcFilePath, const FilePath &tgt /*! Copies a file specified by \a srcFilePath to \a tgtFilePath only if \a srcFilePath is different - (file size and last modification time). + (file contents and last modification time). Returns whether the operation succeeded. */ bool FileUtils::copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgtFilePath) { - if (QFile::exists(tgtFilePath.toString())) { - const QFileInfo srcFileInfo = srcFilePath.toFileInfo(); - const QFileInfo tgtFileInfo = tgtFilePath.toFileInfo(); - if (srcFileInfo.lastModified() == tgtFileInfo.lastModified() && - srcFileInfo.size() == tgtFileInfo.size()) { - return true; - } else { - QFile::remove(tgtFilePath.toString()); + QTC_ASSERT(srcFilePath.exists(), return false); + QTC_ASSERT(srcFilePath.scheme() == tgtFilePath.scheme(), return false); + QTC_ASSERT(srcFilePath.host() == tgtFilePath.host(), return false); + + if (tgtFilePath.exists()) { + const QDateTime srcModified = srcFilePath.lastModified(); + const QDateTime tgtModified = tgtFilePath.lastModified(); + if (srcModified == tgtModified) { + const QByteArray srcContents = srcFilePath.fileContents(); + const QByteArray tgtContents = srcFilePath.fileContents(); + if (srcContents == tgtContents) + return true; } + tgtFilePath.removeFile(); } - return QFile::copy(srcFilePath.toString(), tgtFilePath.toString()); + return srcFilePath.copyFile(tgtFilePath); } /*! |