From 3f4b6d6fc0a6c60e28d66178a53010a602b87280 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 26 Apr 2022 20:54:29 +0200 Subject: [PATCH] fix: Make Stat::same_inode_as consider error code --- src/Stat.hpp | 4 ++-- unittest/test_Stat.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Stat.hpp b/src/Stat.hpp index 2f56214a5..47a085481 100644 --- a/src/Stat.hpp +++ b/src/Stat.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Joel Rosdahl and other contributors +// Copyright (C) 2019-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -171,7 +171,7 @@ inline Stat::operator bool() const inline bool Stat::same_inode_as(const Stat& other) const { - return device() == other.device() && inode() == other.inode(); + return m_errno == 0 && device() == other.device() && inode() == other.inode(); } inline int diff --git a/unittest/test_Stat.cpp b/unittest/test_Stat.cpp index 9253f6857..3a3586e29 100644 --- a/unittest/test_Stat.cpp +++ b/unittest/test_Stat.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Joel Rosdahl and other contributors +// Copyright (C) 2019-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -197,6 +197,8 @@ TEST_CASE("Same i-node as") Util::write_file("a", "change size"); auto new_a_stat = Stat::stat("a"); CHECK(new_a_stat.same_inode_as(a_stat)); + + CHECK(!Stat::stat("nonexistent").same_inode_as(Stat::stat("nonexistent"))); } TEST_CASE("Return values when file is missing") -- 2.47.2