]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Improve disk size calculation on Windows
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 28 Feb 2023 20:46:46 +0000 (21:46 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 4 Mar 2023 09:10:21 +0000 (10:10 +0100)
Windows file system block size is typically 4096 bytes, not 1024.

src/Stat.hpp
unittest/test_Stat.cpp

index 42fe563f5e5d61759b81b2f692638f34cb37244a..5452872a92bdd456057a1ff85ec496d0c7411b11 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -20,6 +20,7 @@
 
 #include <core/wincompat.hpp>
 #include <util/TimePoint.hpp>
+#include <util/file.hpp>
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -250,7 +251,7 @@ inline uint64_t
 Stat::size_on_disk() const
 {
 #ifdef _WIN32
-  return (size() + 1023) & ~1023;
+  return util::likely_size_on_disk(size());
 #else
   return m_stat.st_blocks * 512;
 #endif
index 58830819959273df1b803b2f43dad4c5542dc0af..ffdb68095c1849a98d8a2eea9b6aedd3b8253d1b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -265,7 +265,7 @@ TEST_CASE("Return values when file exists")
   CHECK(stat.mtime().sec() == last_write_time.tv_sec);
   CHECK(stat.mtime().nsec_decimal_part() == last_write_time.tv_nsec);
 
-  CHECK(stat.size_on_disk() == ((stat.size() + 1023) & ~1023));
+  CHECK(stat.size_on_disk() == ((stat.size() + 4095) & ~4095));
   CHECK(stat.file_attributes() == info.dwFileAttributes);
   CHECK(stat.reparse_tag() == 0);