diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-12 23:05:01 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-12 23:05:01 +0000 |
commit | a3e6415ba8cf1b8d2a1db40c06997d997eac8afc (patch) | |
tree | 16e43edf9a785101b562ee3bfa6cbaeb600fc22a /src/libstore | |
parent | b438d37558eab56a2927771013c9080675381ba8 (diff) | |
download | guix-a3e6415ba8cf1b8d2a1db40c06997d997eac8afc.tar.gz |
* 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')
-rw-r--r-- | src/libstore/build.cc | 2 | ||||
-rw-r--r-- | src/libstore/local-store.cc | 42 | ||||
-rw-r--r-- | src/libstore/local-store.hh | 3 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 4 | ||||
-rw-r--r-- | src/libstore/remote-store.hh | 3 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 6 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 10 |
7 files changed, 25 insertions, 45 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 14388a7b56..9bcf336a4f 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -949,7 +949,7 @@ void DerivationGoal::buildDone() as that means that someone else can have interfered with the build. Also, the output should be owned by the build user. */ - if ((st.st_mode & (S_IWGRP | S_IWOTH)) || + if ((!S_ISLNK(st.st_mode) && (st.st_mode & (S_IWGRP | S_IWOTH))) || (buildUser.enabled() && st.st_uid != buildUser.getUID())) throw BuildError(format("suspicious ownership or permission on `%1%'; rejecting this build output") % path); #endif diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 01d1e398c8..1bed672d2c 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)); diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index ef508630ba..8f4ed8fc82 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -50,7 +50,8 @@ public: void queryReferrers(const Path & path, PathSet & referrers); Path addToStore(const Path & srcPath, bool fixed = false, - bool recursive = false, string hashAlgo = ""); + bool recursive = false, string hashAlgo = "", + PathFilter & filter = defaultPathFilter); Path addTextToStore(const string & suffix, const string & s, const PathSet & references); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 504eb52329..e6b34c9b8b 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -213,7 +213,7 @@ void RemoteStore::queryReferrers(const Path & path, Path RemoteStore::addToStore(const Path & _srcPath, bool fixed, - bool recursive, string hashAlgo) + bool recursive, string hashAlgo, PathFilter & filter) { Path srcPath(absPath(_srcPath)); @@ -222,7 +222,7 @@ Path RemoteStore::addToStore(const Path & _srcPath, bool fixed, writeInt(fixed ? 1 : 0, to); writeInt(recursive ? 1 : 0, to); writeString(hashAlgo, to); - dumpPath(srcPath, to); + dumpPath(srcPath, to, filter); processStderr(); Path path = readStorePath(from); return path; diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 82cfb08e95..42d4e94e2a 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -38,7 +38,8 @@ public: void queryReferrers(const Path & path, PathSet & referrers); Path addToStore(const Path & srcPath, bool fixed = false, - bool recursive = false, string hashAlgo = ""); + bool recursive = false, string hashAlgo = "", + PathFilter & filter = defaultPathFilter); Path addTextToStore(const string & suffix, const string & s, const PathSet & references); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 677c3ca3e9..be9ea788bc 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -94,9 +94,9 @@ Path makeFixedOutputPath(bool recursive, std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath, - bool fixed, bool recursive, string hashAlgo) + bool fixed, bool recursive, string hashAlgo, PathFilter & filter) { - Hash h = hashPath(htSHA256, srcPath); + Hash h = hashPath(htSHA256, srcPath, filter); string baseName = baseNameOf(srcPath); @@ -104,7 +104,7 @@ std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath, if (fixed) { HashType ht(parseHashType(hashAlgo)); - Hash h2 = recursive ? hashPath(ht, srcPath) : hashFile(ht, srcPath); + Hash h2 = recursive ? hashPath(ht, srcPath, filter) : hashFile(ht, srcPath); dstPath = makeFixedOutputPath(recursive, hashAlgo, h2, baseName); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 19c5d81cf2..d92b03df06 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -79,9 +79,12 @@ public: /* Copy the contents of a path to the store and register the validity the resulting path. The resulting path is returned. If `fixed' is true, then the output of a fixed-output - derivation is pre-loaded into the Nix store. */ + derivation is pre-loaded into the Nix store. The function + object `filter' can be used to exclude files (see + libutil/archive.hh). */ virtual Path addToStore(const Path & srcPath, bool fixed = false, - bool recursive = false, string hashAlgo = "") = 0; + bool recursive = false, string hashAlgo = "", + PathFilter & filter = defaultPathFilter) = 0; /* Like addToStore, but the contents written to the output path is a regular file containing the given string. */ @@ -195,7 +198,8 @@ Path makeFixedOutputPath(bool recursive, Returns the store path and the cryptographic hash of the contents of srcPath. */ std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath, - bool fixed = false, bool recursive = false, string hashAlgo = ""); + bool fixed = false, bool recursive = false, string hashAlgo = "", + PathFilter & filter = defaultPathFilter); /* Preparatory part of addTextToStore(). |