forked from qt-creator/qt-creator
Utils: Add FilePath::isSameFile()
FilePath::isSameFile() checks if two files are the same file. It first checks if its on the same device. If it is, it will try to read the fileId of the files and compare them. Change-Id: I83668955cacd4e5ed03d43a3fee2be29e9d0a6f0 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -515,6 +515,25 @@ bool FilePath::isSameDevice(const FilePath &other) const
|
||||
return s_deviceHooks.isSameDevice(*this, other);
|
||||
}
|
||||
|
||||
bool FilePath::isSameFile(const FilePath &other) const
|
||||
{
|
||||
if (*this == other)
|
||||
return true;
|
||||
|
||||
if (!isSameDevice(other))
|
||||
return false;
|
||||
|
||||
const QByteArray fileId = fileAccess()->fileId(*this);
|
||||
const QByteArray otherFileId = fileAccess()->fileId(other);
|
||||
if (fileId.isEmpty() || otherFileId.isEmpty())
|
||||
return false;
|
||||
|
||||
if (fileId == otherFileId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// \returns an empty FilePath if this is not a symbolic linl
|
||||
FilePath FilePath::symLinkTarget() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user