about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-01T14·37+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-01T15·14+0200
commitdaf3f2c11ff467b600473a2fda7bd513aacc1efa (patch)
tree2f69efd2cff7f7801b16ebe6a8c5b35cccf90065 /src/libutil/util.cc
parent1c208f2b7ef8ffb5e6d435d703dad83223a67bd6 (diff)
Make readDirectory() return inode / file type
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index f762b79c24da..7dc6fe72a41d 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -203,9 +203,10 @@ bool isLink(const Path & path)
 }
 
 
-Strings readDirectory(const Path & path)
+DirEntries readDirectory(const Path & path)
 {
-    Strings names;
+    DirEntries entries;
+    entries.reserve(64);
 
     AutoCloseDir dir = opendir(path.c_str());
     if (!dir) throw SysError(format("opening directory `%1%'") % path);
@@ -215,11 +216,11 @@ Strings readDirectory(const Path & path)
         checkInterrupt();
         string name = dirent->d_name;
         if (name == "." || name == "..") continue;
-        names.push_back(name);
+        entries.emplace_back(DirEntry({ name, dirent->d_ino, dirent->d_type }));
     }
     if (errno) throw SysError(format("reading directory `%1%'") % path);
 
-    return names;
+    return entries;
 }
 
 
@@ -294,16 +295,14 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
         bytesFreed += st.st_blocks * 512;
 
     if (S_ISDIR(st.st_mode)) {
-        Strings names = readDirectory(path);
-
         /* Make the directory writable. */
         if (!(st.st_mode & S_IWUSR)) {
             if (chmod(path.c_str(), st.st_mode | S_IWUSR) == -1)
                 throw SysError(format("making `%1%' writable") % path);
         }
 
-        for (Strings::iterator i = names.begin(); i != names.end(); ++i)
-            _deletePath(path + "/" + *i, bytesFreed);
+        for (auto & i : readDirectory(path))
+            _deletePath(path + "/" + i.name, bytesFreed);
     }
 
     if (remove(path.c_str()) == -1)