Browse Source

Revise function for checking "same file"

adaptive-webui-19844
Chocobo1 2 years ago
parent
commit
50b01ed45d
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 16
      src/base/utils/fs.cpp

16
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. * 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) bool Utils::Fs::sameFiles(const Path &path1, const Path &path2)
{ {
QFile f1 {path1.data()}; QFile f1 {path1.data()};
QFile f2 {path2.data()}; QFile f2 {path2.data()};
if (!f1.exists() || !f2.exists()) return false;
if (f1.size() != f2.size()) return false; if (!f1.exists() || !f2.exists())
if (!f1.open(QIODevice::ReadOnly)) return false; return false;
if (!f2.open(QIODevice::ReadOnly)) 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 const int readSize = 1024 * 1024; // 1 MiB
while (!f1.atEnd() && !f2.atEnd()) while (!f1.atEnd() && !f2.atEnd())

Loading…
Cancel
Save