mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 22:32:26 +00:00
Move NAR-related commands to 'nix nar'
This commit is contained in:
parent
79c1967ded
commit
ef583303f0
@ -64,13 +64,11 @@ struct CmdCatNar : StoreCommand, MixCat
|
||||
return "print the contents of a file inside a NAR file on stdout";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
cat(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
|
||||
}
|
||||
};
|
||||
|
||||
static auto rCmdCatStore = registerCommand<CmdCatStore>("cat-store");
|
||||
static auto rCmdCatNar = registerCommand<CmdCatNar>("cat-nar");
|
||||
static auto rCmdCatStore = registerCommand2<CmdCatStore>({"store", "cat"});
|
||||
static auto rCmdCatNar = registerCommand2<CmdCatNar>({"nar", "cat"});
|
||||
|
@ -134,7 +134,7 @@ struct CmdLsNar : Command, MixLs
|
||||
return {
|
||||
Example{
|
||||
"To list a specific file in a NAR:",
|
||||
"nix ls-nar -l hello.nar /bin/hello"
|
||||
"nix nar ls -l hello.nar /bin/hello"
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -144,13 +144,11 @@ struct CmdLsNar : Command, MixLs
|
||||
return "show information about a path inside a NAR file";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run() override
|
||||
{
|
||||
list(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
|
||||
}
|
||||
};
|
||||
|
||||
static auto rCmdLsStore = registerCommand<CmdLsStore>("ls-store");
|
||||
static auto rCmdLsNar = registerCommand<CmdLsNar>("ls-nar");
|
||||
static auto rCmdLsStore = registerCommand2<CmdLsStore>({"store", "ls"});
|
||||
static auto rCmdLsNar = registerCommand2<CmdLsNar>({"nar", "ls"});
|
||||
|
31
src/nix/nar.cc
Normal file
31
src/nix/nar.cc
Normal file
@ -0,0 +1,31 @@
|
||||
#include "command.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
struct CmdNar : NixMultiCommand
|
||||
{
|
||||
CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
|
||||
{ }
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "query the contents of NAR files";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run() override
|
||||
{
|
||||
if (!command)
|
||||
throw UsageError("'nix nar' requires a sub-command.");
|
||||
command->second->prepare();
|
||||
command->second->run();
|
||||
}
|
||||
|
||||
void printHelp(const string & programName, std::ostream & out) override
|
||||
{
|
||||
MultiCommand::printHelp(programName, out);
|
||||
}
|
||||
};
|
||||
|
||||
static auto rCmdNar = registerCommand<CmdNar>("nar");
|
@ -196,13 +196,13 @@ narCache=$TEST_ROOT/nar-cache
|
||||
rm -rf $narCache
|
||||
mkdir $narCache
|
||||
|
||||
[[ $(nix cat-store --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
|
||||
[[ $(nix store cat --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
|
||||
|
||||
rm -rfv "$cacheDir/nar"
|
||||
|
||||
[[ $(nix cat-store --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
|
||||
[[ $(nix store cat --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
|
||||
|
||||
(! nix cat-store --store file://$cacheDir $outPath/foobar)
|
||||
(! nix store cat --store file://$cacheDir $outPath/foobar)
|
||||
|
||||
|
||||
# Test NAR listing generation.
|
||||
|
@ -22,9 +22,9 @@ outPath=$(nix-build dependencies.nix --no-out-link --sandbox-paths /nix/store)
|
||||
|
||||
nix path-info -r $outPath | grep input-2
|
||||
|
||||
nix ls-store -R -l $outPath | grep foobar
|
||||
nix store ls -R -l $outPath | grep foobar
|
||||
|
||||
nix cat-store $outPath/foobar | grep FOOBAR
|
||||
nix store cat $outPath/foobar | grep FOOBAR
|
||||
|
||||
# Test --check without hash rewriting.
|
||||
nix-build dependencies.nix --no-out-link --check --sandbox-paths /nix/store
|
||||
|
@ -9,45 +9,45 @@ cd "$TEST_ROOT"
|
||||
narFile="$TEST_ROOT/path.nar"
|
||||
nix-store --dump $storePath > $narFile
|
||||
|
||||
# Check that find and ls-nar match.
|
||||
# Check that find and nar ls match.
|
||||
( cd $storePath; find . | sort ) > files.find
|
||||
nix ls-nar -R -d $narFile "" | sort > files.ls-nar
|
||||
nix nar ls -R -d $narFile "" | sort > files.ls-nar
|
||||
diff -u files.find files.ls-nar
|
||||
|
||||
# Check that file contents of data match.
|
||||
nix cat-nar $narFile /foo/data > data.cat-nar
|
||||
nix nar cat $narFile /foo/data > data.cat-nar
|
||||
diff -u data.cat-nar $storePath/foo/data
|
||||
|
||||
# Check that file contents of baz match.
|
||||
nix cat-nar $narFile /foo/baz > baz.cat-nar
|
||||
nix nar cat $narFile /foo/baz > baz.cat-nar
|
||||
diff -u baz.cat-nar $storePath/foo/baz
|
||||
|
||||
nix cat-store $storePath/foo/baz > baz.cat-nar
|
||||
nix store cat $storePath/foo/baz > baz.cat-nar
|
||||
diff -u baz.cat-nar $storePath/foo/baz
|
||||
|
||||
# Test --json.
|
||||
diff -u \
|
||||
<(nix ls-nar --json $narFile / | jq -S) \
|
||||
<(nix nar ls --json $narFile / | jq -S) \
|
||||
<(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S)
|
||||
diff -u \
|
||||
<(nix ls-nar --json -R $narFile /foo | jq -S) \
|
||||
<(nix nar ls --json -R $narFile /foo | jq -S) \
|
||||
<(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0,"narOffset":368},"baz":{"type":"regular","size":0,"narOffset":552},"data":{"type":"regular","size":58,"narOffset":736}}}' | jq -S)
|
||||
diff -u \
|
||||
<(nix ls-nar --json -R $narFile /foo/bar | jq -S) \
|
||||
<(nix nar ls --json -R $narFile /foo/bar | jq -S) \
|
||||
<(echo '{"type":"regular","size":0,"narOffset":368}' | jq -S)
|
||||
diff -u \
|
||||
<(nix ls-store --json $storePath | jq -S) \
|
||||
<(nix store ls --json $storePath | jq -S) \
|
||||
<(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S)
|
||||
diff -u \
|
||||
<(nix ls-store --json -R $storePath/foo | jq -S) \
|
||||
<(nix store ls --json -R $storePath/foo | jq -S) \
|
||||
<(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0},"baz":{"type":"regular","size":0},"data":{"type":"regular","size":58}}}' | jq -S)
|
||||
diff -u \
|
||||
<(nix ls-store --json -R $storePath/foo/bar| jq -S) \
|
||||
<(nix store ls --json -R $storePath/foo/bar| jq -S) \
|
||||
<(echo '{"type":"regular","size":0}' | jq -S)
|
||||
|
||||
# Test missing files.
|
||||
nix ls-store --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
|
||||
nix ls-store $storePath/xyzzy 2>&1 | grep 'does not exist'
|
||||
nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
|
||||
nix store ls $storePath/xyzzy 2>&1 | grep 'does not exist'
|
||||
|
||||
# Test failure to dump.
|
||||
if nix-store --dump $storePath >/dev/full ; then
|
||||
|
Loading…
Reference in New Issue
Block a user