From 50b01ed45d6d680f8bafc7d396a5f2bc980da4c7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 22 Jul 2022 20:33:52 +0800 Subject: [PATCH] Revise function for checking "same file" --- src/base/utils/fs.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index ac99e40fe..ae0ed75ee 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -162,15 +162,23 @@ qint64 Utils::Fs::computePathSize(const Path &path) /** * Makes deep comparison of two files to make sure they are identical. + * The point is about the file contents. If the files do not exist then + * the paths refers to nothing and therefore we cannot say the files are same + * (because there are no files!) */ bool Utils::Fs::sameFiles(const Path &path1, const Path &path2) { QFile f1 {path1.data()}; QFile f2 {path2.data()}; - if (!f1.exists() || !f2.exists()) return false; - if (f1.size() != f2.size()) return false; - if (!f1.open(QIODevice::ReadOnly)) return false; - if (!f2.open(QIODevice::ReadOnly)) return false; + + if (!f1.exists() || !f2.exists()) + return false; + if (path1 == path2) + return true; + if (f1.size() != f2.size()) + return false; + if (!f1.open(QIODevice::ReadOnly) || !f2.open(QIODevice::ReadOnly)) + return false; const int readSize = 1024 * 1024; // 1 MiB while (!f1.atEnd() && !f2.atEnd())