diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-12T23·05+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-12T23·05+0000 |
commit | a3e6415ba8cf1b8d2a1db40c06997d997eac8afc (patch) | |
tree | 16e43edf9a785101b562ee3bfa6cbaeb600fc22a /src/libstore/local-store.cc | |
parent | b438d37558eab56a2927771013c9080675381ba8 (diff) |
* 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.
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r-- | src/libstore/local-store.cc | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 01d1e398c851..1bed672d2c9a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -171,33 +171,7 @@ void createStoreTransaction(Transaction & txn) } -/* Path copying. */ - -struct CopySink : Sink -{ - string s; - virtual void operator () (const unsigned char * data, unsigned int len) - { - s.append((const char *) data, len); - } -}; - - -struct CopySource : Source -{ - string & s; - unsigned int pos; - CopySource(string & _s) : s(_s), pos(0) { } - virtual void operator () (unsigned char * data, unsigned int len) - { - s.copy((char *) data, len, pos); - pos += len; - assert(pos <= s.size()); - } -}; - - -void copyPath(const Path & src, const Path & dst) +void copyPath(const Path & src, const Path & dst, PathFilter & filter) { debug(format("copying `%1%' to `%2%'") % src % dst); @@ -206,10 +180,10 @@ void copyPath(const Path & src, const Path & dst) for very large paths, but `copyPath' is mainly used for small files. */ - CopySink sink; - dumpPath(src, sink); + StringSink sink; + dumpPath(src, sink, filter); - CopySource source(sink.s); + StringSource source(sink.s); restorePath(dst, source); } @@ -646,13 +620,13 @@ static void invalidatePath(Transaction & txn, const Path & path) Path LocalStore::addToStore(const Path & _srcPath, bool fixed, - bool recursive, string hashAlgo) + bool recursive, string hashAlgo, PathFilter & filter) { Path srcPath(absPath(_srcPath)); debug(format("adding `%1%' to the store") % srcPath); std::pair<Path, Hash> pr = - computeStorePathForPath(srcPath, fixed, recursive, hashAlgo); + computeStorePathForPath(srcPath, fixed, recursive, hashAlgo, filter); Path & dstPath(pr.first); Hash & h(pr.second); @@ -669,9 +643,9 @@ Path LocalStore::addToStore(const Path & _srcPath, bool fixed, if (pathExists(dstPath)) deletePathWrapped(dstPath); - copyPath(srcPath, dstPath); + copyPath(srcPath, dstPath, filter); - Hash h2 = hashPath(htSHA256, dstPath); + Hash h2 = hashPath(htSHA256, dstPath, filter); if (h != h2) throw Error(format("contents of `%1%' changed while copying it to `%2%' (%3% -> %4%)") % srcPath % dstPath % printHash(h) % printHash(h2)); |