]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Make Stat::same_inode_as consider error code
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 26 Apr 2022 18:54:29 +0000 (20:54 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 26 Apr 2022 19:23:32 +0000 (21:23 +0200)
src/Stat.hpp
unittest/test_Stat.cpp

index 2f56214a53d8df4b4ba52312fefab8c2a7a1f430..47a0854811ce3f9336a4fb487ba6fa1578418150 100644 (file)
@@ -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
index 9253f6857df1bd98737495b260b98fcc6a004488..3a3586e29bf8295a5e023da95ab8aadc5dc9272c 100644 (file)
@@ -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")