]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Use Util::traverse in Util::clean_up_internal_tempdir
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 10 May 2020 06:36:47 +0000 (08:36 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 12 May 2020 19:13:50 +0000 (21:13 +0200)
src/ccache.cpp

index 397b45a731aa37d20b45fd1c99ffdd6e85686aa1..0ec38285fcb0f7f65abfcd502dcadf8ff8ced9c5 100644 (file)
@@ -325,34 +325,27 @@ static void
 clean_up_internal_tempdir(const Context& ctx)
 {
   time_t now = time(nullptr);
-  auto st = Stat::stat(ctx.config.cache_dir(), Stat::OnError::log);
-  if (!st || st.mtime() + k_tempdir_cleanup_interval >= now) {
+  auto dir_st = Stat::stat(ctx.config.cache_dir(), Stat::OnError::log);
+  if (!dir_st || dir_st.mtime() + k_tempdir_cleanup_interval >= now) {
     // No cleanup needed.
     return;
   }
 
   update_mtime(ctx.config.cache_dir().c_str());
 
-  DIR* dir = opendir(temp_dir(ctx));
-  if (!dir) {
+  if (!Stat::lstat(temp_dir(ctx))) {
     return;
   }
 
-  struct dirent* entry;
-  while ((entry = readdir(dir))) {
-    if (str_eq(entry->d_name, ".") || str_eq(entry->d_name, "..")) {
-      continue;
+  Util::traverse(temp_dir(ctx), [now](const std::string& path, bool is_dir) {
+    if (is_dir) {
+      return;
     }
-
-    char* path = format("%s/%s", temp_dir(ctx), entry->d_name);
-    st = Stat::lstat(path, Stat::OnError::log);
+    auto st = Stat::lstat(path, Stat::OnError::log);
     if (st && st.mtime() + k_tempdir_cleanup_interval < now) {
-      tmp_unlink(path);
+      tmp_unlink(path.c_str());
     }
-    free(path);
-  }
-
-  closedir(dir);
+  });
 }
 
 static void