]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move File to util::FileStream
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 1 Oct 2023 08:23:18 +0000 (10:23 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 1 Oct 2023 17:02:24 +0000 (19:02 +0200)
src/Context.hpp
src/Logging.cpp
src/ccache.cpp
src/core/Result.cpp
src/core/StatsLog.cpp
src/core/mainoptions.cpp
src/execute.cpp
src/storage/local/LocalStorage.cpp
src/util/FileStream.hpp [moved from src/File.hpp with 68% similarity]

index aeb3e0af8838dd09cdea0e65581ff350b2f6f278..51b4787b878c0a1a5bf9a023aef09f081ef59b10 100644 (file)
@@ -21,9 +21,9 @@
 #include "Args.hpp"
 #include "ArgsInfo.hpp"
 #include "Config.hpp"
-#include "File.hpp"
 #include "MiniTrace.hpp"
 
+#include <util/FileStream.hpp>
 #include <util/NonCopyable.hpp>
 
 #ifdef INODE_CACHE_SUPPORTED
@@ -105,7 +105,7 @@ public:
   pid_t compiler_pid = 0;
 
   // Files used by the hash debugging functionality.
-  std::vector<File> hash_debug_files;
+  std::vector<util::FileStream> hash_debug_files;
 
   // Options to ignore for the hash.
   const std::vector<std::string>& ignore_options() const;
index 4090335f99d66c89ef910c6bc54228261878d5dc..1705024d7876aab05bce56ed6fa42c3667f9f17f 100644 (file)
 #include "Logging.hpp"
 
 #include "Config.hpp"
-#include "File.hpp"
 #include "Util.hpp"
 #include "Win32Util.hpp"
 #include "execute.hpp"
 
+#include <util/FileStream.hpp>
 #include <util/file.hpp>
 #include <util/fmtmacros.hpp>
 #include <util/time.hpp>
@@ -48,7 +48,7 @@ namespace {
 
 // Logfile path and file handle, read from Config::log_file().
 std::string logfile_path;
-File logfile;
+util::FileStream logfile;
 
 // Whether to use syslog() instead.
 bool use_syslog = false;
@@ -182,7 +182,7 @@ dump_log(const std::string& path)
   if (!enabled()) {
     return;
   }
-  File file(path, "w");
+  util::FileStream file(path, "w");
   if (file) {
     (void)fwrite(debug_log_buffer.data(), debug_log_buffer.length(), 1, *file);
   } else {
index ee1497d93f7c37a165b1b7ef407c9c9e8eb63db6..3e1009b4f720721d6b4947d548ee15a4995380c9 100644 (file)
@@ -23,7 +23,6 @@
 #include "ArgsInfo.hpp"
 #include "Context.hpp"
 #include "Depfile.hpp"
-#include "File.hpp"
 #include "Hash.hpp"
 #include "Logging.hpp"
 #include "MiniTrace.hpp"
@@ -49,6 +48,7 @@
 #include <core/types.hpp>
 #include <storage/Storage.hpp>
 #include <util/Fd.hpp>
+#include <util/FileStream.hpp>
 #include <util/Finalizer.hpp>
 #include <util/TemporaryFile.hpp>
 #include <util/UmaskScope.hpp>
@@ -230,7 +230,7 @@ init_hash_debug(Context& ctx,
                                        ctx.time_of_invocation,
                                        ctx.args_info.output_obj,
                                        FMT("input-{}", type));
-  File debug_binary_file(path, "wb");
+  util::FileStream debug_binary_file(path, "wb");
   if (debug_binary_file) {
     hash.enable_debug(section_name, debug_binary_file.get(), debug_text_file);
     ctx.hash_debug_files.push_back(std::move(debug_binary_file));
@@ -2496,7 +2496,7 @@ do_cache_compilation(Context& ctx)
                                          ctx.time_of_invocation,
                                          ctx.args_info.orig_output_obj,
                                          "input-text");
-    File debug_text_file(path, "w");
+    util::FileStream debug_text_file(path, "w");
     if (debug_text_file) {
       ctx.hash_debug_files.push_back(std::move(debug_text_file));
     } else {
index c490aceba31a74c6bcc23abaa288bf4aa5adf505..84bc8fd90fa79284703f67970a28cc8c16ef7bf5 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "Config.hpp"
 #include "Context.hpp"
-#include "File.hpp"
 #include "Logging.hpp"
 #include "Util.hpp"
 
@@ -31,6 +30,7 @@
 #include <core/exceptions.hpp>
 #include <util/Bytes.hpp>
 #include <util/DirEntry.hpp>
+#include <util/FileStream.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
 #include <util/fmtmacros.hpp>
index 71b6455627862e944b3b3c52372ac0a482eef81d..651fbe088ad3b898b62d52f01f8a5067787e897a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,9 +18,9 @@
 
 #include "StatsLog.hpp"
 
-#include <File.hpp>
 #include <Logging.hpp>
 #include <core/Statistics.hpp>
+#include <util/FileStream.hpp>
 #include <util/fmtmacros.hpp>
 
 #include <fstream>
@@ -56,7 +56,7 @@ void
 StatsLog::log_result(const std::string& input_file,
                      const std::vector<std::string>& result_ids)
 {
-  File file(m_path, "ab");
+  util::FileStream file(m_path, "ab");
   if (!file) {
     LOG("Failed to open {}: {}", m_path, strerror(errno));
     return;
index 1e9c85b8a6638912a608fe0012337a9ba999ade1..676433f0f029bb449f64c6bbe59ab37ef910ff69 100644 (file)
@@ -19,7 +19,6 @@
 #include "mainoptions.hpp"
 
 #include <Config.hpp>
-#include <File.hpp>
 #include <Hash.hpp>
 #include <InodeCache.hpp>
 #include <Logging.hpp>
@@ -38,6 +37,7 @@
 #include <storage/Storage.hpp>
 #include <storage/local/LocalStorage.hpp>
 #include <util/Fd.hpp>
+#include <util/FileStream.hpp>
 #include <util/TemporaryFile.hpp>
 #include <util/TextTable.hpp>
 #include <util/ThreadPool.hpp>
index 68450fb09cdf2f2cb3115f5196a98b9a9b81e29f..3eb22193d625e0c406af130b818ba46ea7dbed76 100644 (file)
@@ -92,7 +92,7 @@ win32getshell(const std::string& path)
   }
   if (sh.empty() && getenv("CCACHE_DETECT_SHEBANG")) {
     // Detect shebang.
-    File fp(path, "r");
+    util::FileStream fp(path, "r");
     if (fp) {
       char buf[10] = {0};
       fgets(buf, sizeof(buf) - 1, fp.get());
index d130843a0bdbf79b1109566c5f023c55d1621bc2..4cc50b86d715461d66cbbb66441ad86252ac35c5 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <Config.hpp>
 #include <Context.hpp>
-#include <File.hpp>
 #include <Logging.hpp>
 #include <MiniTrace.hpp>
 #include <Util.hpp>
@@ -32,6 +31,7 @@
 #include <core/common.hpp>
 #include <core/exceptions.hpp>
 #include <util/Duration.hpp>
+#include <util/FileStream.hpp>
 #include <util/TemporaryFile.hpp>
 #include <util/TextTable.hpp>
 #include <util/ThreadPool.hpp>
similarity index 68%
rename from src/File.hpp
rename to src/util/FileStream.hpp
index cb4d177bd5213747839f3031456ea1bc6d0faf87..e50e47a0881b40ae1a16b510de8f647f4c727557 100644 (file)
 #include <cstdio>
 #include <string>
 
-class File : util::NonCopyable
+namespace util {
+
+class FileStream : util::NonCopyable
 {
 public:
-  File() = default;
-  explicit File(FILE* file);
-  File(const std::string& path, const char* mode);
-  File(File&& other) noexcept;
-  ~File();
+  FileStream() = default;
+  explicit FileStream(FILE* file);
+  FileStream(const std::string& path, const char* mode);
+  FileStream(FileStream&& other) noexcept;
+  ~FileStream();
 
-  File& operator=(File&& other) noexcept;
+  FileStream& operator=(FileStream&& other) noexcept;
 
   void open(const std::string& path, const char* mode);
   void close();
@@ -46,16 +48,16 @@ private:
   bool m_owned = false;
 };
 
-inline File::File(FILE* const file) : m_file(file), m_owned(false)
+inline FileStream::FileStream(FILE* const file) : m_file(file), m_owned(false)
 {
 }
 
-inline File::File(const std::string& path, const char* mode)
+inline FileStream::FileStream(const std::string& path, const char* mode)
 {
   open(path, mode);
 }
 
-inline File::File(File&& other) noexcept
+inline FileStream::FileStream(FileStream&& other) noexcept
   : m_file(other.m_file),
     m_owned(other.m_owned)
 {
@@ -63,13 +65,13 @@ inline File::File(File&& other) noexcept
   other.m_owned = false;
 }
 
-inline File::~File()
+inline FileStream::~FileStream()
 {
   close();
 }
 
-inline File&
-File::operator=(File&& other) noexcept
+inline FileStream&
+FileStream::operator=(FileStream&& other) noexcept
 {
   m_file = other.m_file;
   m_owned = other.m_owned;
@@ -79,7 +81,7 @@ File::operator=(File&& other) noexcept
 }
 
 inline void
-File::open(const std::string& path, const char* mode)
+FileStream::open(const std::string& path, const char* mode)
 {
   close();
   m_file = fopen(path.c_str(), mode);
@@ -87,7 +89,7 @@ File::open(const std::string& path, const char* mode)
 }
 
 inline void
-File::close()
+FileStream::close()
 {
   if (m_file && m_owned) {
     fclose(m_file);
@@ -96,19 +98,21 @@ File::close()
   m_owned = false;
 }
 
-inline File::operator bool() const
+inline FileStream::operator bool() const
 {
   return m_file;
 }
 
 inline FILE*
-File::operator*() const
+FileStream::operator*() const
 {
   return m_file;
 }
 
 inline FILE*
-File::get()
+FileStream::get()
 {
   return m_file;
 }
+
+} // namespace util