Merge remote-tracking branch 'me/more-rust-ffi' into no-stringly-typed-derivation-output
This commit is contained in:
+5
-5
@@ -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);
|
||||
@@ -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();
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ struct StorePathsCommand : public InstallablesCommand
|
||||
{
|
||||
private:
|
||||
|
||||
FileIngestionMethod recursive = FileIngestionMethod::Flat;
|
||||
bool recursive = false;
|
||||
bool all = false;
|
||||
|
||||
protected:
|
||||
@@ -101,7 +101,7 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
StorePathsCommand(FileIngestionMethod recursive = FileIngestionMethod::Flat);
|
||||
StorePathsCommand(bool recursive = false);
|
||||
|
||||
using StoreCommand::run;
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ struct CmdCopy : StorePathsCommand
|
||||
SubstituteFlag substitute = NoSubstitute;
|
||||
|
||||
CmdCopy()
|
||||
: StorePathsCommand(FileIngestionMethod::Recursive)
|
||||
: StorePathsCommand(true)
|
||||
{
|
||||
addFlag({
|
||||
.longName = "from",
|
||||
|
||||
+19
-11
@@ -9,15 +9,14 @@ using namespace nix;
|
||||
|
||||
struct CmdHash : Command
|
||||
{
|
||||
enum Mode { mFile, mPath };
|
||||
Mode mode;
|
||||
FileIngestionMethod mode;
|
||||
Base base = SRI;
|
||||
bool truncate = false;
|
||||
HashType ht = htSHA256;
|
||||
std::vector<std::string> paths;
|
||||
std::optional<std::string> modulus;
|
||||
|
||||
CmdHash(Mode mode) : mode(mode)
|
||||
CmdHash(FileIngestionMethod mode) : mode(mode)
|
||||
{
|
||||
mkFlag(0, "sri", "print hash in SRI format", &base, SRI);
|
||||
mkFlag(0, "base64", "print hash in base-64", &base, Base64);
|
||||
@@ -36,9 +35,14 @@ struct CmdHash : Command
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return mode == mFile
|
||||
? "print cryptographic hash of a regular file"
|
||||
: "print cryptographic hash of the NAR serialisation of a path";
|
||||
const char* d;
|
||||
switch (mode) {
|
||||
case FileIngestionMethod::Flat:
|
||||
d = "print cryptographic hash of a regular file";
|
||||
case FileIngestionMethod::Recursive:
|
||||
d = "print cryptographic hash of the NAR serialisation of a path";
|
||||
};
|
||||
return d;
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
@@ -53,10 +57,14 @@ struct CmdHash : Command
|
||||
else
|
||||
hashSink = std::make_unique<HashSink>(ht);
|
||||
|
||||
if (mode == mFile)
|
||||
switch (mode) {
|
||||
case FileIngestionMethod::Flat:
|
||||
readFile(path, *hashSink);
|
||||
else
|
||||
break;
|
||||
case FileIngestionMethod::Recursive:
|
||||
dumpPath(path, *hashSink);
|
||||
break;
|
||||
}
|
||||
|
||||
Hash h = hashSink->finish().first;
|
||||
if (truncate && h.hashSize > 20) h = compressHash(h, 20);
|
||||
@@ -65,8 +73,8 @@ struct CmdHash : Command
|
||||
}
|
||||
};
|
||||
|
||||
static RegisterCommand r1("hash-file", [](){ return make_ref<CmdHash>(CmdHash::mFile); });
|
||||
static RegisterCommand r2("hash-path", [](){ return make_ref<CmdHash>(CmdHash::mPath); });
|
||||
static RegisterCommand r1("hash-file", [](){ return make_ref<CmdHash>(FileIngestionMethod::Flat); });
|
||||
static RegisterCommand r2("hash-path", [](){ return make_ref<CmdHash>(FileIngestionMethod::Recursive); });
|
||||
|
||||
struct CmdToBase : Command
|
||||
{
|
||||
@@ -137,7 +145,7 @@ static int compatNixHash(int argc, char * * argv)
|
||||
});
|
||||
|
||||
if (op == opHash) {
|
||||
CmdHash cmd(flat ? CmdHash::mFile : CmdHash::mPath);
|
||||
CmdHash cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive);
|
||||
cmd.ht = ht;
|
||||
cmd.base = base32 ? Base32 : Base16;
|
||||
cmd.truncate = truncate;
|
||||
|
||||
Reference in New Issue
Block a user