]> git.ipfire.org Git - pakfire.git/commitdiff
util: Speed up pakfire_rmtree()
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 17:53:08 +0000 (17:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 17:53:08 +0000 (17:53 +0000)
We can already call rmdir() if we know that we have a directory instead
of trying unlink() first and then falling back.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c

index ff8523a7aad9737e72f97cbb8e2b897f592bd10f..e051d3abc61cffb9ed53f4f5beb78f2751e7b27b 100644 (file)
@@ -1054,8 +1054,14 @@ char* pakfire_mkdtemp(char* path) {
        return mkdtemp(path);
 }
 
-static int _unlink(const char* path, const struct stat* stat, int typeflag, struct FTW* ftwbuf) {
-       return remove(path);
+static int _unlink(const char* path, const struct stat* stat,
+               const int type, struct FTW* ftwbuf) {
+       // Delete directories using rmdir()
+       if (type & FTW_D)
+               return rmdir(path);
+
+       // unlink() everything else
+       return unlink(path);
 }
 
 int pakfire_rmtree(const char* path, int flags) {