]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Rename file_size to file_size_on_disk and improve its return type
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 6 Oct 2019 14:05:20 +0000 (16:05 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 7 Oct 2019 07:37:59 +0000 (09:37 +0200)
src/ccache.cpp
src/ccache.hpp
src/cleanup.cpp
src/compress.cpp
src/legacy_util.cpp
src/result.cpp

index 80e1367619c54748f187ee1bd1b81b82db3ff36e..8c8c3dbc0d11b192e10b620f3d8785430de0aca9 100644 (file)
@@ -1189,9 +1189,9 @@ update_manifest_file(void)
   }
 
   struct stat st;
-  size_t old_size = 0; // in bytes
+  uint64_t old_size = 0; // in bytes
   if (stat(manifest_path, &st) == 0) {
-    old_size = file_size(&st);
+    old_size = file_size_on_disk(&st);
   }
 
   MTR_BEGIN("manifest", "manifest_put");
@@ -1199,8 +1199,9 @@ update_manifest_file(void)
   if (!manifest_put(manifest_path, *cached_result_name, g_included_files)) {
     cc_log("Failed to add result name to %s", manifest_path);
   } else if (x_stat(manifest_path, &st) == 0) {
-    stats_update_size(
-      manifest_stats_file, file_size(&st) - old_size, old_size == 0 ? 1 : 0);
+    stats_update_size(manifest_stats_file,
+                      file_size_on_disk(&st) - old_size,
+                      old_size == 0 ? 1 : 0);
   }
   MTR_END("manifest", "manifest_put");
 }
@@ -1467,10 +1468,11 @@ to_cache(struct args* args, struct hash* depend_mode_hash)
     stats_update(STATS_ERROR);
     failed();
   }
-  stats_update_size(stats_file,
-                    file_size(&st)
-                      - (orig_dest_existed ? file_size(&orig_dest_st) : 0),
-                    orig_dest_existed ? 0 : 1);
+  stats_update_size(
+    stats_file,
+    file_size_on_disk(&st)
+      - (orig_dest_existed ? file_size_on_disk(&orig_dest_st) : 0),
+    orig_dest_existed ? 0 : 1);
 
   MTR_END("file", "file_put");
 
index f41e0fe7026329bb5d6e5103c58ac3440ab84c42..6efe9a4466556d88bc9262db448672a3f128a5fa 100644 (file)
@@ -183,7 +183,7 @@ char* x_basename(const char* path);
 char* x_dirname(const char* path);
 const char* get_extension(const char* path);
 char* remove_extension(const char* path);
-size_t file_size(const struct stat* st);
+uint64_t file_size_on_disk(const struct stat* st);
 char* format_human_readable_size(uint64_t size);
 char* format_parsable_size_with_suffix(uint64_t size);
 bool parse_size_with_suffix(const char* str, uint64_t* size);
index 5062742278554bd26e6958dfd831769039044332..7f04e73a019b79d17170c034a8ccec33bba49764 100644 (file)
@@ -28,7 +28,7 @@
 
 static void
 delete_file(const std::string& path,
-            size_t size,
+            uint64_t size,
             uint64_t* cache_size,
             uint32_t* files_in_cache)
 {
@@ -78,7 +78,7 @@ clean_up_dir(const std::string& subdir,
       continue;
     }
 
-    cache_size += file_size(&file->stat());
+    cache_size += file_size_on_disk(&file->stat());
     files_in_cache += 1;
   }
 
@@ -128,8 +128,10 @@ clean_up_dir(const std::string& subdir,
       delete_file(o_file, 0, nullptr, nullptr);
     }
 
-    delete_file(
-      file->path(), file_size(&file->stat()), &cache_size, &files_in_cache);
+    delete_file(file->path(),
+                file_size_on_disk(&file->stat()),
+                &cache_size,
+                &files_in_cache);
     cleaned = true;
   }
 
index 6cbd37c010f4d5075025880576770e75beb499bf..d5c75abd89260a96885bd731008b792435757ecd 100644 (file)
@@ -68,7 +68,7 @@ compress_stats(const Config& config,
       for (size_t i = 0; i < files.size(); ++i) {
         const auto& file = files[i];
 
-        on_disk_size += file_size(&file->stat());
+        on_disk_size += file_size_on_disk(&file->stat());
 
         uint64_t content_size = 0;
         bool is_compressible;
index 651ccb199a924a42cbd5222ad23efe4966409bf1..943175994914cb2d60b725331ed4ebc87c4a1ab5 100644 (file)
@@ -889,8 +889,8 @@ remove_extension(const char* path)
 }
 
 // Return size on disk of a file.
-size_t
-file_size(const struct stat* st)
+uint64_t
+file_size_on_disk(const struct stat* st)
 {
 #ifdef _WIN32
   return (st->st_size + 1023) & ~1023;
index ca17a78825997e53d9840b4d78792b611c335c5a..18c95968954ea24c4217bcaccfea659e232c5107 100644 (file)
@@ -364,10 +364,10 @@ write_embedded_file_entry(CacheEntryWriter& writer,
     throw Error(fmt::format("Failed to open {} for reading", source_path));
   }
 
-  size_t remain = source_file_size;
+  uint64_t remain = source_file_size;
   while (remain > 0) {
     uint8_t buf[READ_BUFFER_SIZE];
-    size_t n = std::min(remain, sizeof(buf));
+    size_t n = std::min(remain, static_cast<uint64_t>(sizeof(buf)));
     if (fread(buf, n, 1, file.get()) != 1) {
       throw Error(fmt::format("Error reading from {}", source_path));
     }
@@ -391,8 +391,8 @@ write_raw_file_entry(CacheEntryWriter& writer,
       fmt::format("Failed to stat {}: {}", source_path, strerror(errno)));
   }
 
-  size_t old_size;
-  size_t new_size;
+  uint64_t old_size;
+  uint64_t new_size;
 
   cc_log("Storing raw file #%u %s (%llu bytes) from %s",
          entry_number,
@@ -415,8 +415,8 @@ write_raw_file_entry(CacheEntryWriter& writer,
   struct stat new_stat;
   bool new_exists = stat(raw_file.c_str(), &new_stat) == 0;
 
-  old_size = old_existed ? file_size(&old_stat) : 0;
-  new_size = new_exists ? file_size(&new_stat) : 0;
+  old_size = old_existed ? file_size_on_disk(&old_stat) : 0;
+  new_size = new_exists ? file_size_on_disk(&new_stat) : 0;
   stats_update_size(stats_file,
                     new_size - old_size,
                     (new_exists ? 1 : 0) - (old_existed ? 1 : 0));