* 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:
parent
b438d37558
commit
a3e6415ba8
19 changed files with 143 additions and 68 deletions
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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().
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue