]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Keep argument lists and function implementations sorted
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 26 Jul 2020 18:20:37 +0000 (20:20 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 26 Jul 2020 18:32:55 +0000 (20:32 +0200)
src/Util.cpp
src/Util.hpp
src/ccache.cpp
src/cleanup.cpp
src/cleanup.hpp
unittest/test_Util.cpp

index 05403aa460426acbe4f294c02e96f956d1c08f02..774cfe8f4b294ae418b4d58c519c90ee6be1cdeb 100644 (file)
@@ -654,6 +654,40 @@ normalize_absolute_path(string_view path)
 #endif
 }
 
+unsigned
+parse_duration_with_suffix_to_seconds(const std::string& value)
+{
+  size_t end;
+  long result;
+  bool failed = false;
+
+  try {
+    result = std::stol(value, &end, 10);
+  } catch (std::exception&) {
+    failed = true;
+  }
+
+  if (failed || result < 0) {
+    throw Error(fmt::format("invalid unsigned integer: \"{}\"", value));
+  }
+
+  if (end + 1 != value.size()) {
+    throw Error(
+      fmt::format("Invalid suffix, Supported: d(ay)/s(econd): \"{}\"", value));
+  }
+
+  switch (value[end]) {
+  case 'd':
+    result *= 24 * 3600;
+  case 's':
+    break;
+  default:
+    throw Error(
+      fmt::format("Invalid suffix, Supported: d(ay)/s(econd): \"{}\"", value));
+  }
+  return result;
+}
+
 int
 parse_int(const std::string& value)
 {
@@ -998,37 +1032,4 @@ write_file(const std::string& path,
   file << data;
 }
 
-unsigned
-parse_duration_with_suffix_to_seconds(const std::string& value)
-{
-  size_t end;
-  long result;
-  bool failed = false;
-
-  try {
-    result = std::stol(value, &end, 10);
-  } catch (std::exception&) {
-    failed = true;
-  }
-
-  if (failed || result < 0) {
-    throw Error(fmt::format("invalid unsigned integer: \"{}\"", value));
-  }
-
-  if (end + 1 != value.size()) {
-    throw Error(
-      fmt::format("Invalid suffix, Supported: d(ay)/s(econd): \"{}\"", value));
-  }
-
-  switch (value[end]) {
-  case 'd':
-    result *= 24 * 3600;
-  case 's':
-    break;
-  default:
-    throw Error(
-      fmt::format("Invalid suffix, Supported: d(ay)/s(econd): \"{}\"", value));
-  }
-  return result;
-}
 } // namespace Util
index f3c23f0435d910dd046dfb29a2f79c206d988a01..3f3c519fd5f5e3591aa9317a4930eccb09e37df5 100644 (file)
@@ -260,6 +260,13 @@ bool matches_dir_prefix_or_file(nonstd::string_view dir_prefix_or_file,
 // On Windows: Backslashes are replaced with forward slashes.
 std::string normalize_absolute_path(nonstd::string_view path);
 
+// Parse the given string into an unsigned integer. Then based on suffix
+// provided convert the number to seconds possible suffixes = d(ays)/s(econds)
+//
+// Throws `Error` for any other suffix
+// Throws `Error` if parse value is <0
+unsigned parse_duration_with_suffix_to_seconds(const std::string& value);
+
 // Parse a string into an integer.
 //
 // Throws Error on error.
@@ -353,11 +360,4 @@ void write_file(const std::string& path,
                 const std::string& data,
                 std::ios_base::openmode open_mode = std::ios::binary);
 
-// Parse the given string into an unsigned integer. Then based on suffix
-// provided convert the number to seconds possible suffixes = d(ays)/s(econds)
-//
-// Throws `Error` for any other suffix
-// Throws `Error` if parse value is <0
-unsigned parse_duration_with_suffix_to_seconds(const std::string& value);
-
 } // namespace Util
index 7e23c5201a06ad232059a90418611b2ff96b1737..7584d1e335dd20331a901d15d4015882fb7b7b78 100644 (file)
@@ -2200,8 +2200,8 @@ handle_main_options(int argc, const char* const* argv)
   enum longopts {
     DUMP_MANIFEST,
     DUMP_RESULT,
-    EXTRACT_RESULT,
     EVICT_OLDER_THAN,
+    EXTRACT_RESULT,
     HASH_FILE,
     PRINT_STATS,
   };
@@ -2210,8 +2210,8 @@ handle_main_options(int argc, const char* const* argv)
     {"clear", no_argument, nullptr, 'C'},
     {"dump-manifest", required_argument, nullptr, DUMP_MANIFEST},
     {"dump-result", required_argument, nullptr, DUMP_RESULT},
-    {"extract-result", required_argument, nullptr, EXTRACT_RESULT},
     {"evict-older-than", required_argument, nullptr, EVICT_OLDER_THAN},
+    {"extract-result", required_argument, nullptr, EXTRACT_RESULT},
     {"get-config", required_argument, nullptr, 'k'},
     {"hash-file", required_argument, nullptr, HASH_FILE},
     {"help", no_argument, nullptr, 'h'},
@@ -2251,16 +2251,6 @@ handle_main_options(int argc, const char* const* argv)
       return error ? EXIT_FAILURE : EXIT_SUCCESS;
     }
 
-    case EXTRACT_RESULT: {
-      ResultExtractor result_extractor(".");
-      Result::Reader result_reader(optarg);
-      auto error = result_reader.read(result_extractor);
-      if (error) {
-        fmt::print(stderr, "Error: {}\n", *error);
-      }
-      return error ? EXIT_FAILURE : EXIT_SUCCESS;
-    }
-
     case EVICT_OLDER_THAN: {
       unsigned seconds = Util::parse_duration_with_suffix_to_seconds(optarg);
       ProgressBar progress_bar("Clearing ...");
@@ -2272,6 +2262,16 @@ handle_main_options(int argc, const char* const* argv)
       break;
     }
 
+    case EXTRACT_RESULT: {
+      ResultExtractor result_extractor(".");
+      Result::Reader result_reader(optarg);
+      auto error = result_reader.read(result_extractor);
+      if (error) {
+        fmt::print(stderr, "Error: {}\n", *error);
+      }
+      return error ? EXIT_FAILURE : EXIT_SUCCESS;
+    }
+
     case HASH_FILE: {
       Hash hash;
       if (str_eq(optarg, "-")) {
index 4b83ae1e658a586cc5f458effe43a6fff743b260..5f5e9ab50ff5c18ecf415db53fcd418322102905 100644 (file)
@@ -52,6 +52,20 @@ delete_file(const std::string& path,
   }
 }
 
+void
+clean_old(const Context& ctx,
+          const Util::ProgressReceiver& progress_receiver,
+          time_t max_age)
+{
+  Util::for_each_level_1_subdir(
+    ctx.config.cache_dir(),
+    [&](const std::string& subdir,
+        const Util::ProgressReceiver& sub_progress_receiver) {
+      clean_up_dir(subdir, 0, 0, max_age, sub_progress_receiver);
+    },
+    progress_receiver);
+}
+
 // Clean up one cache subdirectory.
 void
 clean_up_dir(const std::string& subdir,
@@ -205,17 +219,3 @@ wipe_all(const Context& ctx, const Util::ProgressReceiver& progress_receiver)
   ctx.inode_cache.drop();
 #endif
 }
-
-void
-clean_old(const Context& ctx,
-          const Util::ProgressReceiver& progress_receiver,
-          time_t max_age)
-{
-  Util::for_each_level_1_subdir(
-    ctx.config.cache_dir(),
-    [&](const std::string& subdir,
-        const Util::ProgressReceiver& sub_progress_receiver) {
-      clean_up_dir(subdir, 0, 0, max_age, sub_progress_receiver);
-    },
-    progress_receiver);
-}
index 5148bf91ef3d506d06d1bed0853bfa638216db58..750bcd47ceed2f866e5be5accbaaf467d1c7dbbc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 class Config;
 class Context;
 
+void clean_old(const Context& ctx,
+               const Util::ProgressReceiver& progress_receiver,
+               time_t max_age);
+
 void clean_up_dir(const std::string& subdir,
                   uint64_t max_size,
                   uint32_t max_files,
@@ -38,7 +42,3 @@ void clean_up_all(const Config& config,
 
 void wipe_all(const Context& ctx,
               const Util::ProgressReceiver& progress_receiver);
-
-void clean_old(const Context& ctx,
-               const Util::ProgressReceiver& progress_receiver,
-               time_t max_age);
index a1644e01c94cbbeb0b0a525354ef759d516fae79..f299bad52dd14d5afe08769720a3f412e9e6a4c0 100644 (file)
@@ -498,6 +498,20 @@ TEST_CASE("Util::normalize_absolute_path")
 #endif
 }
 
+TEST_CASE("Util::parse_duration_with_suffix_to_seconds")
+{
+  CHECK(Util::parse_duration_with_suffix_to_seconds("0s") == 0);
+  CHECK(Util::parse_duration_with_suffix_to_seconds("2s") == 2);
+  CHECK(Util::parse_duration_with_suffix_to_seconds("1d") == 3600 * 24);
+  CHECK(Util::parse_duration_with_suffix_to_seconds("2d") == 2 * 3600 * 24);
+  CHECK_THROWS_WITH(Util::parse_duration_with_suffix_to_seconds("-2"),
+                    "invalid unsigned integer: \"-2\"");
+  CHECK_THROWS_WITH(Util::parse_duration_with_suffix_to_seconds("2x"),
+                    "Invalid suffix, Supported: d(ay)/s(econd): \"2x\"");
+  CHECK_THROWS_WITH(Util::parse_duration_with_suffix_to_seconds("2"),
+                    "Invalid suffix, Supported: d(ay)/s(econd): \"2\"");
+}
+
 TEST_CASE("Util::parse_int")
 {
   CHECK(Util::parse_int("0") == 0);
@@ -792,18 +806,4 @@ TEST_CASE("Util::wipe_path")
   }
 }
 
-TEST_CASE("Util::parse_duration_with_suffix_to_seconds")
-{
-  CHECK(Util::parse_duration_with_suffix_to_seconds("0s") == 0);
-  CHECK(Util::parse_duration_with_suffix_to_seconds("2s") == 2);
-  CHECK(Util::parse_duration_with_suffix_to_seconds("1d") == 3600 * 24);
-  CHECK(Util::parse_duration_with_suffix_to_seconds("2d") == 2 * 3600 * 24);
-  CHECK_THROWS_WITH(Util::parse_duration_with_suffix_to_seconds("-2"),
-                    "invalid unsigned integer: \"-2\"");
-  CHECK_THROWS_WITH(Util::parse_duration_with_suffix_to_seconds("2x"),
-                    "Invalid suffix, Supported: d(ay)/s(econd): \"2x\"");
-  CHECK_THROWS_WITH(Util::parse_duration_with_suffix_to_seconds("2"),
-                    "Invalid suffix, Supported: d(ay)/s(econd): \"2\"");
-}
-
 TEST_SUITE_END();