wsd: refactor FileUtil::Stat::isUpToDate

Historically, isUpToDate was created and used
in jail setup. But since in other cases we
might also need to compare files, we break
it into two functions. A new member called
isIdenticalTo, which simply does the comparison
and returns the result, and isUpToDate, which
calls isIdenticalTo and logs the result, as
expected by the jail management.

Change-Id: I6581970ad3e97e3fc0728055e6b57647baedf968
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2023-05-10 08:16:52 -04:00 committed by Michael Meeks
parent 3825205042
commit 6f0a5dce5b

View file

@ -217,6 +217,18 @@ namespace FileUtil
/// Returns true iff the path exists, regardless of access permission.
bool exists() const { return good() || (_errno != ENOENT && _errno != ENOTDIR); }
/// Returns true if both files exist and have
/// the same size and same contents.
bool isIdenticalTo(const Stat& other) const
{
// No need to check whether they are linked or not,
// since if they are, the following check will match,
// and if they aren't, we still need to rely on the following.
// Finally, compare the contents, to avoid costly copying if we fail to update.
return (exists() && other.exists() && !isDirectory() && !other.isDirectory() &&
size() == other.size() && compareFileContents(_path, other._path));
}
/// Returns true if both files exist and have
/// the same size and modified timestamp.
bool isUpToDate(const Stat& other) const
@ -225,8 +237,7 @@ namespace FileUtil
// since if they are, the following check will match,
// and if they aren't, we still need to rely on the following.
// Finally, compare the contents, to avoid costly copying if we fail to update.
if (exists() && other.exists() && !isDirectory() && !other.isDirectory()
&& size() == other.size() && compareFileContents(_path, other._path))
if (isIdenticalTo(other))
{
return true;
}