]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use std::string in InodeCache APIs
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 29 Jul 2020 17:15:58 +0000 (19:15 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 29 Jul 2020 17:15:58 +0000 (19:15 +0200)
src/InodeCache.cpp
src/InodeCache.hpp
unittest/test_InodeCache.cpp

index a8a9c9d663ce8393409ce3fa0b1a6d295bddeb8a..b75c52dbdf3b0756d20c6b9fd57a1aa4931ebda2 100644 (file)
@@ -170,11 +170,14 @@ InodeCache::mmap_file(const std::string& inode_cache_file)
 }
 
 bool
-InodeCache::hash_inode(const char* path, ContentType type, Digest& digest)
+InodeCache::hash_inode(const std::string& path,
+                       ContentType type,
+                       Digest& digest)
 {
   Stat stat = Stat::stat(path);
   if (!stat) {
-    cc_log("Could not stat %s: %s", path, strerror(stat.error_number()));
+    cc_log(
+      "Could not stat %s: %s", path.c_str(), strerror(stat.error_number()));
     return false;
   }
 
@@ -356,7 +359,7 @@ InodeCache::~InodeCache()
 }
 
 bool
-InodeCache::get(const char* path,
+InodeCache::get(const std::string& path,
                 ContentType type,
                 Digest& file_digest,
                 int* return_value)
@@ -396,7 +399,7 @@ InodeCache::get(const char* path,
   }
   release_bucket(bucket);
 
-  cc_log("inode cache %s: %s", found ? "hit" : "miss", path);
+  cc_log("inode cache %s: %s", found ? "hit" : "miss", path.c_str());
 
   if (m_config.debug()) {
     if (found) {
@@ -414,7 +417,7 @@ InodeCache::get(const char* path,
 }
 
 bool
-InodeCache::put(const char* path,
+InodeCache::put(const std::string& path,
                 ContentType type,
                 const Digest& file_digest,
                 int return_value)
@@ -444,7 +447,7 @@ InodeCache::put(const char* path,
 
   release_bucket(bucket);
 
-  cc_log("inode cache insert: %s", path);
+  cc_log("inode cache insert: %s", path.c_str());
 
   return true;
 }
index 1c0fdf06f39a43e232ecbabe0e83808c60431b5d..dce36d629957d8df4def742ae9fb515dc7437b93 100644 (file)
@@ -50,7 +50,7 @@ public:
   //
   // Returns true if saved values could be retrieved from the cache, false
   // otherwise.
-  bool get(const char* path,
+  bool get(const std::string& path,
            ContentType type,
            Digest& file_digest,
            int* return_value = nullptr);
@@ -59,7 +59,7 @@ public:
   // hash_source_code_file().
   //
   // Returns true if values could be stored in the cache, false otherwise.
-  bool put(const char* path,
+  bool put(const std::string& path,
            ContentType type,
            const Digest& file_digest,
            int return_value = 0);
@@ -97,7 +97,8 @@ private:
   struct SharedRegion;
 
   bool mmap_file(const std::string& inode_cache_file);
-  static bool hash_inode(const char* path, ContentType type, Digest& digest);
+  static bool
+  hash_inode(const std::string& path, ContentType type, Digest& digest);
   Bucket* acquire_bucket(uint32_t index);
   Bucket* acquire_bucket(const Digest& key_digest);
   static void release_bucket(Bucket* bucket);
index b158c7537af2947ee3e05be88411210993a0db37..124d337c9c375b0809ee04a7f80f7cde92f00d49 100644 (file)
@@ -30,11 +30,14 @@ using TestUtil::TestContext;
 namespace {
 
 bool
-put(const Context& ctx, const char* filename, const char* s, int return_value)
+put(const Context& ctx,
+    const std::string& filename,
+    const std::string& str,
+    int return_value)
 {
   return ctx.inode_cache.put(filename,
                              InodeCache::ContentType::code,
-                             Hash().hash(s).digest(),
+                             Hash().hash(str).digest(),
                              return_value);
 }