mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Revise function for checking "same file"
This commit is contained in:
parent
727d20cc92
commit
50b01ed45d
@ -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…
Reference in New Issue
Block a user