forked from qt-creator/qt-creator
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 <david.schulz@qt.io>
This commit is contained in:
@@ -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
|
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.
|
Returns whether the operation succeeded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool FileUtils::copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgtFilePath)
|
bool FileUtils::copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgtFilePath)
|
||||||
{
|
{
|
||||||
if (QFile::exists(tgtFilePath.toString())) {
|
QTC_ASSERT(srcFilePath.exists(), return false);
|
||||||
const QFileInfo srcFileInfo = srcFilePath.toFileInfo();
|
QTC_ASSERT(srcFilePath.scheme() == tgtFilePath.scheme(), return false);
|
||||||
const QFileInfo tgtFileInfo = tgtFilePath.toFileInfo();
|
QTC_ASSERT(srcFilePath.host() == tgtFilePath.host(), return false);
|
||||||
if (srcFileInfo.lastModified() == tgtFileInfo.lastModified() &&
|
|
||||||
srcFileInfo.size() == tgtFileInfo.size()) {
|
if (tgtFilePath.exists()) {
|
||||||
return true;
|
const QDateTime srcModified = srcFilePath.lastModified();
|
||||||
} else {
|
const QDateTime tgtModified = tgtFilePath.lastModified();
|
||||||
QFile::remove(tgtFilePath.toString());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Reference in New Issue
Block a user