]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Do `rm -r cache/*` instead of `rm -r cache` on reset
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 14 Oct 2024 22:33:59 +0000 (16:33 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 14 Oct 2024 22:35:35 +0000 (16:35 -0600)
Skips a pointless warning on the logs when dropping an incompatible
cache:

> Cannot delete .: Invalid argument

src/cache.c

index 0d3dbe205a7d58c3f609d7e89cd67ca34af8ef02..fcdde56204e7971940a89d611ad84a76e041fc99 100644 (file)
@@ -153,6 +153,41 @@ init_tables(void)
        init_table(&cache.fallback, "fallback", true, NULL);
 }
 
+static int
+reset_cache_dir(void)
+{
+       DIR *dir;
+       struct dirent *file;
+       int error;
+       unsigned int deleted;
+
+       pr_op_debug("Resetting cache...");
+
+       dir = opendir(".");
+       if (dir == NULL)
+               goto fail;
+
+       deleted = 0;
+       FOREACH_DIR_FILE(dir, file)
+               if (!S_ISDOTS(file)) {
+                       error = file_rm_rf(file->d_name);
+                       if (error)
+                               goto end;
+                       deleted++;
+               }
+       if (errno)
+               goto fail;
+
+       pr_op_debug(deleted > 0 ? "Cache cleared." : "Cache was empty.");
+       error = 0;
+       goto end;
+
+fail:  error = errno;
+       pr_op_err("Cannot traverse the cache: %s", strerror(error));
+end:   closedir(dir);
+       return error;
+}
+
 static void
 init_cache_metafile(void)
 {
@@ -194,7 +229,7 @@ init_cache_metafile(void)
 invalid_cache:
        pr_op_info("The cache seems to have been built by a different version of Fort. "
            "I'm going to clear it, just to be safe.");
-       file_rm_rf(".");
+       reset_cache_dir();
        json_decref(root);
 }