1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 13:41:15 +02:00

* New primop builtins.filterSource, which can be used to filter files

from a source directory.  All files for which a predicate function
  returns true are copied to the store.  Typical example is to leave
  out the .svn directory:

    stdenv.mkDerivation {
      ...
      src = builtins.filterSource
        (path: baseNameOf (toString path) != ".svn")
        ./source-dir;
      # as opposed to
      #   src = ./source-dir;
    }

  This is important because the .svn directory influences the hash in
  a rather unpredictable and variable way.
This commit is contained in:
Eelco Dolstra 2006-12-12 23:05:01 +00:00
parent b438d37558
commit a3e6415ba8
19 changed files with 143 additions and 68 deletions

View file

@ -18,28 +18,29 @@ namespace nix {
static string archiveVersion1 = "nix-archive-1";
DumpFilter defaultDumpFilter;
PathFilter defaultPathFilter;
static void dump(const string & path, Sink & sink, DumpFilter & filter);
static void dump(const string & path, Sink & sink, PathFilter & filter);
static void dumpEntries(const Path & path, Sink & sink, DumpFilter & filter)
static void dumpEntries(const Path & path, Sink & sink, PathFilter & filter)
{
Strings names = readDirectory(path);
vector<string> names2(names.begin(), names.end());
sort(names2.begin(), names2.end());
for (vector<string>::iterator it = names2.begin();
it != names2.end(); it++)
for (vector<string>::iterator i = names2.begin();
i != names2.end(); ++i)
{
if (filter(path)) {
Path entry = path + "/" + *i;
if (filter(entry)) {
writeString("entry", sink);
writeString("(", sink);
writeString("name", sink);
writeString(*it, sink);
writeString(*i, sink);
writeString("node", sink);
dump(path + "/" + *it, sink, filter);
dump(entry, sink, filter);
writeString(")", sink);
}
}
@ -69,7 +70,7 @@ static void dumpContents(const Path & path, unsigned int size,
}
static void dump(const Path & path, Sink & sink, DumpFilter & filter)
static void dump(const Path & path, Sink & sink, PathFilter & filter)
{
struct stat st;
if (lstat(path.c_str(), &st))
@ -106,7 +107,7 @@ static void dump(const Path & path, Sink & sink, DumpFilter & filter)
}
void dumpPath(const Path & path, Sink & sink, DumpFilter & filter)
void dumpPath(const Path & path, Sink & sink, PathFilter & filter)
{
writeString(archiveVersion1, sink);
dump(path, sink, filter);