]> git.ipfire.org Git - pakfire.git/commitdiff
util: Store errno when running pakfire_rmtree()
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Jul 2022 08:24:32 +0000 (08:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Jul 2022 08:24:32 +0000 (08:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c

index 7bcc0d3e511f930f8a4a771ffcb9e355f013c917..7d94f0fef989e3d2f197b36ccab7edae7f1f0eb5 100644 (file)
@@ -987,12 +987,19 @@ static int _unlink(const char* path, const struct stat* stat, int typeflag, stru
 }
 
 int pakfire_rmtree(const char* path, int flags) {
+       // Save errno
+       int saved_errno = errno;
+
+       // Walk through the entire tree and unlink everything
        int r = nftw(path, _unlink, 64, flags|FTW_DEPTH|FTW_PHYS);
 
        // Ignore if path didn't exist
        if (r < 0 && errno == ENOENT)
                r = 0;
 
+       // Restore errno
+       errno = saved_errno;
+
        return r;
 }