From aeb810b01e17d040f9592681ee271f15874dce50 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 12 Jul 2013 14:01:25 +0200 Subject: Garbage collector: Don't follow symlinks arbitrarily Only indirect roots (symlinks to symlinks to the Nix store) are now supported. --- src/libutil/util.cc | 9 +++++++++ src/libutil/util.hh | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'src/libutil') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index b1231e45574f..dad5f624bd00 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -148,6 +148,15 @@ string baseNameOf(const Path & path) } +bool isInDir(const Path & path, const Path & dir) +{ + return path[0] == '/' + && string(path, 0, dir.size()) == dir + && path.size() >= dir.size() + 2 + && path[dir.size()] == '/'; +} + + struct stat lstat(const Path & path) { struct stat st; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 9caab4aa1067..6c83987c5d46 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -45,6 +45,10 @@ Path dirOf(const Path & path); following the final `/'. */ string baseNameOf(const Path & path); +/* Check whether a given path is a descendant of the given + directory. */ +bool isInDir(const Path & path, const Path & dir); + /* Get status of `path'. */ struct stat lstat(const Path & path); -- cgit 1.4.1