forked from lix-project/lix
* In dumpPath(): pass a function object that allows files to be
selectively in/excluded from the dump.
This commit is contained in:
parent
3130f1f0fa
commit
b438d37558
|
@ -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,14 +33,16 @@ static void dumpEntries(const Path & path, Sink & sink)
|
|||
for (vector<string>::iterator it = names2.begin();
|
||||
it != names2.end(); it++)
|
||||
{
|
||||
if (filter(path)) {
|
||||
writeString("entry", sink);
|
||||
writeString("(", sink);
|
||||
writeString("name", sink);
|
||||
writeString(*it, sink);
|
||||
writeString("node", sink);
|
||||
dump(path + "/" + *it, 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,7 +45,16 @@ namespace nix {
|
|||
|
||||
`+' denotes string concatenation. */
|
||||
|
||||
void dumpPath(const Path & path, Sink & sink);
|
||||
struct DumpFilter
|
||||
{
|
||||
virtual ~DumpFilter() { }
|
||||
virtual bool operator () (const Path & path) { return true; }
|
||||
};
|
||||
|
||||
extern DumpFilter defaultDumpFilter;
|
||||
|
||||
void dumpPath(const Path & path, Sink & sink,
|
||||
DumpFilter & filter = defaultDumpFilter);
|
||||
|
||||
void restorePath(const Path & path, Source & source);
|
||||
|
||||
|
|
Loading…
Reference in a new issue