summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-02-28 21:46:46 +0100
committerJoel Rosdahl <joel@rosdahl.net>2023-03-04 10:10:21 +0100
commit5c700eac69f1e9751d86bedf36d9a842c3d7283f (patch)
tree233f5c2c27ef541674f28e8ee253427c17a308e0
parente7489b70d16d218470cb5ce45766bdfa38d6db91 (diff)
downloadccache-5c700eac69f1e9751d86bedf36d9a842c3d7283f.tar.gz
feat: Improve disk size calculation on Windows
Windows file system block size is typically 4096 bytes, not 1024.
-rw-r--r--src/Stat.hpp5
-rw-r--r--unittest/test_Stat.cpp4
2 files changed, 5 insertions, 4 deletions
diff --git a/src/Stat.hpp b/src/Stat.hpp
index 42fe563f..5452872a 100644
--- a/src/Stat.hpp
+++ b/src/Stat.hpp
@@ -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
diff --git a/unittest/test_Stat.cpp b/unittest/test_Stat.cpp
index 58830819..ffdb6809 100644
--- a/unittest/test_Stat.cpp
+++ b/unittest/test_Stat.cpp
@@ -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);