From: Joel Rosdahl Date: Tue, 28 Feb 2023 20:46:46 +0000 (+0100) Subject: feat: Improve disk size calculation on Windows X-Git-Tag: v4.8~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c700eac69f1e9751d86bedf36d9a842c3d7283f;p=thirdparty%2Fccache.git feat: Improve disk size calculation on Windows Windows file system block size is typically 4096 bytes, not 1024. --- diff --git a/src/Stat.hpp b/src/Stat.hpp index 42fe563f5..5452872a9 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 #include +#include #include #include @@ -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 588308199..ffdb68095 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);