mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-30 22:36:50 +01:00
daemon: Micro-optimize 'deletePath'.
'remove' calls 'unlink' first and falls back to 'rmdir' upon EISDIR. This change gets rid of the 'unlink' call for every directory being removed. * nix/libutil/util.cc (_deletePath): Call 'unlink' or 'rmdir' depending on 'st.st_mode', rather than call 'remove'.
This commit is contained in:
parent
256c3e714a
commit
24224530d1
1 changed files with 6 additions and 3 deletions
|
@ -337,12 +337,15 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed, size
|
||||||
for (auto & i : readDirectory(path))
|
for (auto & i : readDirectory(path))
|
||||||
_deletePath(path + "/" + i.name, bytesFreed, linkThreshold);
|
_deletePath(path + "/" + i.name, bytesFreed, linkThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
ret = S_ISDIR(st.st_mode) ? rmdir(path.c_str()) : unlink(path.c_str());
|
||||||
|
if (ret == -1)
|
||||||
|
throw SysError(format("cannot unlink `%1%'") % path);
|
||||||
|
|
||||||
#undef st_mode
|
#undef st_mode
|
||||||
#undef st_size
|
#undef st_size
|
||||||
#undef st_nlink
|
#undef st_nlink
|
||||||
|
|
||||||
if (remove(path.c_str()) == -1)
|
|
||||||
throw SysError(format("cannot unlink `%1%'") % path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue