From c6a97e3b74289fdc8e57189212a0db3d0e6896e0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 24 Nov 2006 20:24:14 +0000 Subject: * Doh! Path sizes need to be computed recursively of course. (NIX-70) --- src/libutil/util.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/libutil/util.cc') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 38e32bfa9b58..f80fb7dbf766 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -238,6 +238,29 @@ void writeFile(const Path & path, const string & s) } +unsigned long long computePathSize(const Path & path) +{ + unsigned long long size = 0; + + checkInterrupt(); + + struct stat st; + if (lstat(path.c_str(), &st)) + throw SysError(format("getting attributes of path `%1%'") % path); + + size += st.st_size; + + if (S_ISDIR(st.st_mode)) { + Strings names = readDirectory(path); + + for (Strings::iterator i = names.begin(); i != names.end(); ++i) + size += computePathSize(path + "/" + *i); + } + + return size; +} + + static void _deletePath(const Path & path, unsigned long long & bytesFreed) { checkInterrupt(); -- cgit 1.4.1