about summary refs log tree commit diff
path: root/src/libutil/archive.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-12-12T21·51+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-12-12T21·51+0000
commitb438d37558eab56a2927771013c9080675381ba8 (patch)
tree712ef93c6c82e7f502eeac1283f4844a010314f3 /src/libutil/archive.cc
parent3130f1f0fa484495ebca89bd458cf7fffa522687 (diff)
* In dumpPath(): pass a function object that allows files to be
  selectively in/excluded from the dump.

Diffstat (limited to 'src/libutil/archive.cc')
-rw-r--r--src/libutil/archive.cc31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc
index e3bd63db0b4d..4aedd31f7672 100644
--- a/src/libutil/archive.cc
+++ b/src/libutil/archive.cc
@@ -18,10 +18,13 @@ namespace nix {
 static string archiveVersion1 = "nix-archive-1";
 
 
-static void dump(const string & path, Sink & sink);
+DumpFilter defaultDumpFilter;
 
 
-static void dumpEntries(const Path & path, Sink & sink)
+static void dump(const string & path, Sink & sink, DumpFilter & filter);
+
+
+static void dumpEntries(const Path & path, Sink & sink, DumpFilter & filter)
 {
     Strings names = readDirectory(path);
     vector<string> names2(names.begin(), names.end());
@@ -30,13 +33,15 @@ static void dumpEntries(const Path & path, Sink & sink)
     for (vector<string>::iterator it = names2.begin();
          it != names2.end(); it++)
     {
-        writeString("entry", sink);
-        writeString("(", sink);
-        writeString("name", sink);
-        writeString(*it, sink);
-        writeString("node", sink);
-        dump(path + "/" + *it, sink);
-        writeString(")", sink);
+        if (filter(path)) {
+            writeString("entry", sink);
+            writeString("(", sink);
+            writeString("name", sink);
+            writeString(*it, sink);
+            writeString("node", sink);
+            dump(path + "/" + *it, sink, filter);
+            writeString(")", sink);
+        }
     }
 }
 
@@ -64,7 +69,7 @@ static void dumpContents(const Path & path, unsigned int size,
 }
 
 
-static void dump(const Path & path, Sink & sink)
+static void dump(const Path & path, Sink & sink, DumpFilter & filter)
 {
     struct stat st;
     if (lstat(path.c_str(), &st))
@@ -85,7 +90,7 @@ static void dump(const Path & path, Sink & sink)
     else if (S_ISDIR(st.st_mode)) {
         writeString("type", sink);
         writeString("directory", sink);
-        dumpEntries(path, sink);
+        dumpEntries(path, sink, filter);
     }
 
     else if (S_ISLNK(st.st_mode)) {
@@ -101,10 +106,10 @@ static void dump(const Path & path, Sink & sink)
 }
 
 
-void dumpPath(const Path & path, Sink & sink)
+void dumpPath(const Path & path, Sink & sink, DumpFilter & filter)
 {
     writeString(archiveVersion1, sink);
-    dump(path, sink);
+    dump(path, sink, filter);
 }