summaryrefslogtreecommitdiff
path: root/nix/libutil/util.cc
diff options
context:
space:
mode:
authorMarius Bakke <[email protected]>2019-12-05 17:57:35 +0100
committerMarius Bakke <[email protected]>2019-12-05 17:57:35 +0100
commit9d5aa009062a49bd035ae33e37f6562526e7d38c (patch)
tree4ff2302863a5cf9f3cf604240ea793152156f532 /nix/libutil/util.cc
parent60bd56c6d8368c23dcd97b26501771c82316fc8c (diff)
parent2c2fc24b899d3286774f60405888718d98211213 (diff)
Merge branch 'master' into core-updates
Diffstat (limited to 'nix/libutil/util.cc')
-rw-r--r--nix/libutil/util.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 9a83876013..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);
@@ -306,7 +311,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 +337,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);