From fbecb5cddb2d36cc1a29dac3751b017fa531383c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 26 Nov 2019 23:51:11 +0100 Subject: daemon: 'deletePath' uses 'statx' when available. * nix/libutil/util.cc (_deletePath) [HAVE_STATX]: Use 'statx'. --- nix/libutil/util.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'nix/libutil/util.cc') diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 9a83876013..8093b4c8b4 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc @@ -306,7 +306,18 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed) printMsg(lvlVomit, format("%1%") % path); +#ifdef HAVE_STATX +# define st_mode stx_mode +# define st_size stx_size +# define st_nlink stx_nlink + struct statx st; + if (statx(AT_FDCWD, path.c_str(), + AT_SYMLINK_NOFOLLOW, + STATX_SIZE | STATX_NLINK | STATX_MODE, &st) == -1) + throw SysError(format("getting status of `%1%'") % path); +#else struct stat st = lstat(path); +#endif if (!S_ISDIR(st.st_mode) && st.st_nlink == 1) bytesFreed += st.st_size; @@ -321,6 +332,9 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed) for (auto & i : readDirectory(path)) _deletePath(path + "/" + i.name, bytesFreed); } +#undef st_mode +#undef st_size +#undef st_nlink if (remove(path.c_str()) == -1) throw SysError(format("cannot unlink `%1%'") % path); -- cgit v1.2.3 From b6b014bf42f68fcb71d37204328babb81e0e0855 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 29 Nov 2019 13:54:36 +0100 Subject: daemon: 'pathExists' uses 'statx' when available. * nix/libutil/util.cc (pathExists) [HAVE_STATX]: New code. --- nix/libutil/util.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nix/libutil/util.cc') diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 8093b4c8b4..faba3789df 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc @@ -177,8 +177,13 @@ struct stat lstat(const Path & path) bool pathExists(const Path & path) { int res; +#ifdef HAVE_STATX + struct statx st; + res = statx(AT_FDCWD, path.c_str(), AT_SYMLINK_NOFOLLOW, 0, &st); +#else struct stat st; res = lstat(path.c_str(), &st); +#endif if (!res) return true; if (errno != ENOENT && errno != ENOTDIR) throw SysError(format("getting status of %1%") % path); -- cgit v1.2.3