Skip to content

Commit

Permalink
Merge remote-tracking branch 'me/enum-FileIngestionMethod' into ipfs-…
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
Ericson2314 committed May 27, 2020
2 parents f59cf88 + c66441a commit 807a649
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
14 changes: 7 additions & 7 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu


static void addPath(EvalState & state, const Pos & pos, const string & name, const Path & path_,
Value * filterFun, FileIngestionMethod recursive, const Hash & expectedHash, Value & v)
Value * filterFun, FileIngestionMethod method, const Hash & expectedHash, Value & v)
{
const auto path = evalSettings.pureEval && expectedHash ?
path_ :
Expand Down Expand Up @@ -1073,12 +1073,12 @@ static void addPath(EvalState & state, const Pos & pos, const string & name, con

std::optional<StorePath> expectedStorePath;
if (expectedHash)
expectedStorePath = state.store->makeFixedOutputPath(recursive, expectedHash, name);
expectedStorePath = state.store->makeFixedOutputPath(method, expectedHash, name);
Path dstPath;
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
dstPath = state.store->printStorePath(settings.readOnlyMode
? state.store->computeStorePathForPath(name, path, recursive, htSHA256, filter).first
: state.store->addToStore(name, path, recursive, htSHA256, filter, state.repair));
? state.store->computeStorePathForPath(name, path, method, htSHA256, filter).first
: state.store->addToStore(name, path, method, htSHA256, filter, state.repair));
if (expectedHash && expectedStorePath != state.store->parseStorePath(dstPath))
throw Error("store path mismatch in (possibly filtered) path added from '%s'", path);
} else
Expand Down Expand Up @@ -1108,7 +1108,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
Path path;
string name;
Value * filterFun = nullptr;
auto recursive = FileIngestionMethod::Recursive;
auto method = FileIngestionMethod::Recursive;
Hash expectedHash;

for (auto & attr : *args[0]->attrs) {
Expand All @@ -1124,7 +1124,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
state.forceValue(*attr.value, pos);
filterFun = attr.value;
} else if (n == "recursive")
recursive = FileIngestionMethod { state.forceBool(*attr.value, *attr.pos) };
method = FileIngestionMethod { state.forceBool(*attr.value, *attr.pos) };
else if (n == "sha256")
expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
else
Expand All @@ -1135,7 +1135,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
if (name.empty())
name = baseNameOf(path);

addPath(state, pos, name, path, filterFun, recursive, expectedHash, v);
addPath(state, pos, name, path, filterFun, method, expectedHash, v);
}


Expand Down
6 changes: 3 additions & 3 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
}

StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath,
FileIngestionMethod recursive, HashType hashAlgo, PathFilter & filter, RepairFlag repair)
FileIngestionMethod method, HashType hashAlgo, PathFilter & filter, RepairFlag repair)
{
// FIXME: some cut&paste from LocalStore::addToStore().

Expand All @@ -336,7 +336,7 @@ StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath
small files. */
StringSink sink;
Hash h;
if (recursive == FileIngestionMethod::Recursive) {
if (method == FileIngestionMethod::Recursive) {
dumpPath(srcPath, sink, filter);
h = hashString(hashAlgo, *sink.s);
} else {
Expand All @@ -345,7 +345,7 @@ StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath
h = hashString(hashAlgo, s);
}

ValidPathInfo info(makeFixedOutputPath(recursive, h, name));
ValidPathInfo info(makeFixedOutputPath(method, h, name));

addToStore(info, sink.s, repair, CheckSigs, nullptr);

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public:
std::shared_ptr<FSAccessor> accessor) override;

StorePath addToStore(const string & name, const Path & srcPath,
FileIngestionMethod recursive, HashType hashAlgo,
FileIngestionMethod method, HashType hashAlgo,
PathFilter & filter, RepairFlag repair) override;

StorePath addTextToStore(const string & name, const string & s,
Expand Down
18 changes: 9 additions & 9 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ struct RestrictedStore : public LocalFSStore
{ throw Error("queryPathFromHashPart"); }

StorePath addToStore(const string & name, const Path & srcPath,
FileIngestionMethod recursive = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256,
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256,
PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) override
{ throw Error("addToStore"); }

Expand All @@ -2747,9 +2747,9 @@ struct RestrictedStore : public LocalFSStore
}

StorePath addToStoreFromDump(const string & dump, const string & name,
FileIngestionMethod recursive = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override
{
auto path = next->addToStoreFromDump(dump, name, recursive, hashAlgo, repair);
auto path = next->addToStoreFromDump(dump, name, method, hashAlgo, repair);
goal.addDependency(path);
return path;
}
Expand Down Expand Up @@ -3692,10 +3692,10 @@ void DerivationGoal::registerOutputs()

if (fixedOutput) {

FileIngestionMethod recursive; Hash h;
i.second.parseHashInfo(recursive, h);
FileIngestionMethod outputHashMode; Hash h;
i.second.parseHashInfo(outputHashMode, h);

if (recursive == FileIngestionMethod::Flat) {
if (outputHashMode == FileIngestionMethod::Flat) {
/* The output path should be a regular file without execute permission. */
if (!S_ISREG(st.st_mode) || (st.st_mode & S_IXUSR) != 0)
throw BuildError(
Expand All @@ -3705,11 +3705,11 @@ void DerivationGoal::registerOutputs()

/* Check the hash. In hash mode, move the path produced by
the derivation to its content-addressed location. */
Hash h2 = recursive == FileIngestionMethod::Recursive
Hash h2 = outputHashMode == FileIngestionMethod::Recursive
? hashPath(h.type, actualPath).first
: hashFile(h.type, actualPath);

auto dest = worker.store.makeFixedOutputPath(recursive, h2, i.second.path.name());
auto dest = worker.store.makeFixedOutputPath(outputHashMode, h2, i.second.path.name());

if (h != h2) {

Expand Down Expand Up @@ -3738,7 +3738,7 @@ void DerivationGoal::registerOutputs()
else
assert(worker.store.parseStorePath(path) == dest);

ca = makeFixedOutputCA(recursive, h2);
ca = makeFixedOutputCA(outputHashMode, h2);
}

/* Get rid of all weird permissions. This also checks that
Expand Down
22 changes: 11 additions & 11 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,10 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
if (out == drv.outputs.end())
throw Error("derivation '%s' does not have an output named 'out'", printStorePath(drvPath));

FileIngestionMethod recursive; Hash h;
out->second.parseHashInfo(recursive, h);
FileIngestionMethod method; Hash h;
out->second.parseHashInfo(method, h);

check(makeFixedOutputPath(recursive, h, drvName), out->second.path, "out");
check(makeFixedOutputPath(method, h, drvName), out->second.path, "out");
}

else {
Expand Down Expand Up @@ -1043,11 +1043,11 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,


StorePath LocalStore::addToStoreFromDump(const string & dump, const string & name,
FileIngestionMethod recursive, HashType hashAlgo, RepairFlag repair)
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair)
{
Hash h = hashString(hashAlgo, dump);

auto dstPath = makeFixedOutputPath(recursive, h, name);
auto dstPath = makeFixedOutputPath(method, h, name);

addTempRoot(dstPath);

Expand All @@ -1067,7 +1067,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam

autoGC();

if (recursive == FileIngestionMethod::Recursive) {
if (method == FileIngestionMethod::Recursive) {
StringSource source(dump);
restorePath(realPath, source);
} else
Expand All @@ -1080,7 +1080,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam
above (if called with recursive == true and hashAlgo ==
sha256); otherwise, compute it here. */
HashResult hash;
if (recursive == FileIngestionMethod::Recursive) {
if (method == FileIngestionMethod::Recursive) {
hash.first = hashAlgo == htSHA256 ? h : hashString(htSHA256, dump);
hash.second = dump.size();
} else
Expand All @@ -1091,7 +1091,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam
ValidPathInfo info(dstPath.clone());
info.narHash = hash.first;
info.narSize = hash.second;
info.ca = makeFixedOutputCA(recursive, h);
info.ca = makeFixedOutputCA(method, h);
registerValidPath(info);
}

Expand All @@ -1103,20 +1103,20 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam


StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
FileIngestionMethod recursive, HashType hashAlgo, PathFilter & filter, RepairFlag repair)
FileIngestionMethod method, HashType hashAlgo, PathFilter & filter, RepairFlag repair)
{
Path srcPath(absPath(_srcPath));

/* Read the whole path into memory. This is not a very scalable
method for very large paths, but `copyPath' is mainly used for
small files. */
StringSink sink;
if (recursive == FileIngestionMethod::Recursive)
if (method == FileIngestionMethod::Recursive)
dumpPath(srcPath, sink, filter);
else
sink.s = make_ref<std::string>(readFile(srcPath));

return addToStoreFromDump(*sink.s, name, recursive, hashAlgo, repair);
return addToStoreFromDump(*sink.s, name, method, hashAlgo, repair);
}


Expand Down
6 changes: 3 additions & 3 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ StorePath Store::makeTextPath(std::string_view name, const Hash & hash,


std::pair<StorePath, Hash> Store::computeStorePathForPath(std::string_view name,
const Path & srcPath, FileIngestionMethod recursive, HashType hashAlgo, PathFilter & filter) const
const Path & srcPath, FileIngestionMethod method, HashType hashAlgo, PathFilter & filter) const
{
Hash h = recursive == FileIngestionMethod::Recursive
Hash h = method == FileIngestionMethod::Recursive
? hashPath(hashAlgo, srcPath, filter).first
: hashFile(hashAlgo, srcPath);
return std::make_pair(makeFixedOutputPath(recursive, h, name), h);
return std::make_pair(makeFixedOutputPath(method, h, name), h);
}


Expand Down
10 changes: 5 additions & 5 deletions src/nix/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ void StoreCommand::run()
run(getStore());
}

StorePathsCommand::StorePathsCommand(FileIngestionMethod recursive)
StorePathsCommand::StorePathsCommand(bool recursive)
: recursive(recursive)
{
if (recursive == FileIngestionMethod::Recursive)
if (recursive)
addFlag({
.longName = "no-recursive",
.description = "apply operation to specified paths only",
.handler = {&this->recursive, FileIngestionMethod::Flat},
.handler = {&this->recursive, false},
});
else
addFlag({
.longName = "recursive",
.shortName = 'r',
.description = "apply operation to closure of the specified paths",
.handler = {&this->recursive, FileIngestionMethod::Recursive},
.handler = {&this->recursive, true},
});

mkFlag(0, "all", "apply operation to the entire store", &all);
Expand All @@ -66,7 +66,7 @@ void StorePathsCommand::run(ref<Store> store)
for (auto & p : toStorePaths(store, realiseMode, installables))
storePaths.push_back(p.clone());

if (recursive == FileIngestionMethod::Recursive) {
if (recursive) {
StorePathSet closure;
store->computeFSClosure(storePathsToSet(storePaths), closure, false, false);
storePaths.clear();
Expand Down
4 changes: 2 additions & 2 deletions src/nix/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct StorePathsCommand : public InstallablesCommand
{
private:

FileIngestionMethod recursive = FileIngestionMethod::Flat;
bool recursive = false;
bool all = false;

protected:
Expand All @@ -101,7 +101,7 @@ protected:

public:

StorePathsCommand(FileIngestionMethod recursive = FileIngestionMethod::Flat);
StorePathsCommand(bool recursive = false);

using StoreCommand::run;

Expand Down
2 changes: 1 addition & 1 deletion src/nix/copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CmdCopy : StorePathsCommand
SubstituteFlag substitute = NoSubstitute;

CmdCopy()
: StorePathsCommand(FileIngestionMethod::Recursive)
: StorePathsCommand(true)
{
addFlag({
.longName = "from",
Expand Down

0 comments on commit 807a649

Please sign in to comment.