forked from lix-project/lix
* Added a command ‘nix-store --verify-paths PATHS’ to check whether
the contents of any of the given store paths have been modified. E.g. $ nix-store --verify-path $(nix-store -qR /var/run/current-system) path `/nix/store/m2smyiwbxidlprfxfz4rjlvz2c3mg58y-etc' was modified! expected hash `fc87e271c5fdf179b47939b08ad13440493805584b35e3014109d04d8436e7b8', got `20f1a47281b3c0cbe299ce47ad5ca7340b20ab34246426915fce0ee9116483aa' All paths are checked; the exit code is 1 if any path has been modified, 0 otherwise.
This commit is contained in:
parent
82710f96f7
commit
e6cb3d0a0d
|
@ -40,6 +40,10 @@
|
||||||
<para>TODO: Nix expression search path (<literal>import <foo/bar.nix></literal>).</para>
|
<para>TODO: Nix expression search path (<literal>import <foo/bar.nix></literal>).</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>TODO: <command>nix-store --verify-path</command> command.</para>
|
||||||
|
</listitem>
|
||||||
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -187,12 +187,11 @@ static void initAndRun(int argc, char * * argv)
|
||||||
ignore options for the ATerm library. */
|
ignore options for the ATerm library. */
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
||||||
string arg = *i;
|
string arg = *i;
|
||||||
if (string(arg, 0, 4) == "-at-") ;
|
if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-' && !isdigit(arg[1])) {
|
||||||
else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-' && !isdigit(arg[1])) {
|
|
||||||
for (unsigned int j = 1; j < arg.length(); j++)
|
for (unsigned int j = 1; j < arg.length(); j++)
|
||||||
if (isalpha(arg[j]))
|
if (isalpha(arg[j]))
|
||||||
remaining.push_back((string) "-" + arg[j]);
|
remaining.push_back((string) "-" + arg[j]);
|
||||||
else {
|
else {
|
||||||
remaining.push_back(string(arg, j));
|
remaining.push_back(string(arg, j));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -332,6 +331,9 @@ static void * oomHandler(size_t requested)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int exitCode = 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -390,7 +392,5 @@ int main(int argc, char * * argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,9 @@ struct RemoveTempRoots
|
||||||
~RemoveTempRoots();
|
~RemoveTempRoots();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Exit code of the program. */
|
||||||
|
extern int exitCode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ Operations:
|
||||||
valid
|
valid
|
||||||
|
|
||||||
--verify: verify Nix structures
|
--verify: verify Nix structures
|
||||||
|
--verify-path: verify whether the given store paths haven't been modified
|
||||||
--optimise: optimise the Nix store by hard-linking identical files
|
--optimise: optimise the Nix store by hard-linking identical files
|
||||||
|
|
||||||
--query-failed-paths: list paths that failed to build (if enabled)
|
--query-failed-paths: list paths that failed to build (if enabled)
|
||||||
|
|
|
@ -466,11 +466,12 @@ static void opCheckValidity(Strings opFlags, Strings opArgs)
|
||||||
i != opArgs.end(); ++i)
|
i != opArgs.end(); ++i)
|
||||||
{
|
{
|
||||||
Path path = followLinksToStorePath(*i);
|
Path path = followLinksToStorePath(*i);
|
||||||
if (!store->isValidPath(path))
|
if (!store->isValidPath(path)) {
|
||||||
if (printInvalid)
|
if (printInvalid)
|
||||||
cout << format("%1%\n") % path;
|
cout << format("%1%\n") % path;
|
||||||
else
|
else
|
||||||
throw Error(format("path `%1%' is not valid") % path);
|
throw Error(format("path `%1%' is not valid") % path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,6 +649,27 @@ static void opVerify(Strings opFlags, Strings opArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Verify whether the contents of the given store path have not changed. */
|
||||||
|
static void opVerifyPath(Strings opFlags, Strings opArgs)
|
||||||
|
{
|
||||||
|
if (!opFlags.empty())
|
||||||
|
throw UsageError("no flags expected");
|
||||||
|
|
||||||
|
foreach (Strings::iterator, i, opArgs) {
|
||||||
|
Path path = followLinksToStorePath(*i);
|
||||||
|
printMsg(lvlTalkative, format("checking path `%1%'...") % path);
|
||||||
|
ValidPathInfo info = store->queryPathInfo(path);
|
||||||
|
HashResult current = hashPath(info.hash.type, path);
|
||||||
|
if (current.first != info.hash) {
|
||||||
|
printMsg(lvlError,
|
||||||
|
format("path `%1%' was modified! expected hash `%2%', got `%3%'")
|
||||||
|
% path % printHash(info.hash) % printHash(current.first));
|
||||||
|
exitCode = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void showOptimiseStats(OptimiseStats & stats)
|
static void showOptimiseStats(OptimiseStats & stats)
|
||||||
{
|
{
|
||||||
printMsg(lvlError,
|
printMsg(lvlError,
|
||||||
|
@ -750,6 +772,8 @@ void run(Strings args)
|
||||||
op = opInit;
|
op = opInit;
|
||||||
else if (arg == "--verify")
|
else if (arg == "--verify")
|
||||||
op = opVerify;
|
op = opVerify;
|
||||||
|
else if (arg == "--verify-path")
|
||||||
|
op = opVerifyPath;
|
||||||
else if (arg == "--optimise")
|
else if (arg == "--optimise")
|
||||||
op = opOptimise;
|
op = opOptimise;
|
||||||
else if (arg == "--query-failed-paths")
|
else if (arg == "--query-failed-paths")
|
||||||
|
|
Loading…
Reference in a new issue