]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix copying of binary files on Windows (#979)
authorR. Voggenauer <rvogg@users.noreply.github.com>
Sun, 19 Dec 2021 20:07:58 +0000 (21:07 +0100)
committerGitHub <noreply@github.com>
Sun, 19 Dec 2021 20:07:58 +0000 (21:07 +0100)
src/Util.cpp
test/suites/secondary_file.bash
unittest/test_Util.cpp

index 2219048533584b74d01b61d440866c584ce17238..f03ba6fbea50b67c71cf1e0a156c908ea64aec74 100644 (file)
@@ -355,7 +355,7 @@ copy_fd(int fd_in, int fd_out)
 void
 copy_file(const std::string& src, const std::string& dest, bool via_tmp_file)
 {
-  Fd src_fd(open(src.c_str(), O_RDONLY));
+  Fd src_fd(open(src.c_str(), O_RDONLY | O_BINARY));
   if (!src_fd) {
     throw core::Error("{}: {}", src, strerror(errno));
   }
index 94ff43db28747c116e28038d9042ef20324ece22..3ab48f973e2b8b72ade323b302859f44488f0e6e 100644 (file)
@@ -51,6 +51,15 @@ SUITE_secondary_file() {
     expect_stat files_in_cache 2 # fetched from secondary
     expect_file_count 3 '*' secondary # CACHEDIR.TAG + result + manifest
 
+    $CCACHE_COMPILE -c test.c
+    expect_stat direct_cache_hit 3
+    expect_stat cache_miss 1
+    expect_stat primary_storage_hit 4
+    expect_stat primary_storage_miss 4 # 2 * (result + manifest)
+    expect_stat secondary_storage_hit 2 # result + manifest
+    expect_stat secondary_storage_miss 2 # result + manifest
+    expect_stat files_in_cache 2 # fetched from secondary
+    expect_file_count 3 '*' secondary # CACHEDIR.TAG + result + manifest
     # -------------------------------------------------------------------------
     TEST "Flat layout"
 
index afe7e1cc2d457b09b87a531771988f2a7fb2828d..218927278a7c419358fecea7e0654d30a3b712b1 100644 (file)
@@ -651,6 +651,25 @@ TEST_CASE("Util::read_file and Util::write_file")
                     "No such file or directory");
 }
 
+TEST_CASE(
+  "Util::read_file, Util::write_file and Util::copy_file with binary files")
+{
+  TestContext test_context;
+
+  std::string origin_data;
+  for (int i = 0; i < 512; i++) {
+    origin_data.push_back(static_cast<char>((32 + i) % 256));
+  }
+
+  Util::write_file("test", origin_data, std::ios_base::binary);
+  std::string data = Util::read_file("test");
+  CHECK(data == origin_data);
+
+  Util::copy_file("test", "copy");
+  data = Util::read_file("copy");
+  CHECK(data == origin_data);
+}
+
 TEST_CASE("Util::remove_extension")
 {
   CHECK(Util::remove_extension("") == "");