1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 12:10:59 +01:00
This commit is contained in:
Wouter den Breejen 2007-09-19 14:26:16 +00:00
parent f435abcdb6
commit 4c32f38047
13 changed files with 125 additions and 14 deletions

View file

@ -178,7 +178,7 @@ static void initAndRun(int argc, char * * argv)
buildVerbosity = lvlVomit;
//we need to push back since arguments need to be passed on in the state wrapper script
else if (arg == "--help") {
else if (arg == "--help" && programId != "nix-state") {
printHelp();
remaining.push_back(arg);
}

View file

@ -1837,6 +1837,11 @@ Path toNonSharedPathTxn(const Transaction & txn, const Path & statePath)
return returnedPath;
}
bool LocalStore::getSharedWith(const Path & statePath1, Path & statePath2)
{
return querySharedStateTxn(noTxn, statePath1, statePath2);
}
PathSet toNonSharedPathSetTxn(const Transaction & txn, const PathSet & statePaths)
{
PathSet real_statePaths;

View file

@ -110,6 +110,8 @@ public:
void scanAndUpdateAllReferences(const Path & statePath, const bool recursive);
bool getSharedWith(const Path & statePath1, Path & statePath2);
PathSet toNonSharedPathSet(const PathSet & statePaths);
void revertToRevision(const Path & statePath, const unsigned int revision_arg, const bool recursive);

View file

@ -286,7 +286,6 @@ Path RemoteStore::addTextToStore(const string & suffix, const string & s,
writeString(suffix, to);
writeString(s, to);
writeStringSet(references, to);
processStderr();
return readStorePath(from);
}
@ -310,7 +309,6 @@ Path RemoteStore::importPath(bool requireSignature, Source & source)
anyway. */
processStderr(0, &source);
//Path path = readStorePath(from); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove
return readStorePath(from);
}
@ -504,6 +502,15 @@ void RemoteStore::scanAndUpdateAllReferences(const Path & statePath, const bool
readInt(from);
}
bool RemoteStore::getSharedWith(const Path & statePath1, Path & statePath2)
{
writeInt(wopGetSharedWith, to);
writeString(statePath1, to);
processStderr();
statePath2 = readString(from);
unsigned int reply = readInt(from);
return reply != 0;
}
PathSet RemoteStore::toNonSharedPathSet(const PathSet & statePaths)
{

View file

@ -96,6 +96,8 @@ public:
void scanAndUpdateAllReferences(const Path & statePath, const bool recursive);
bool getSharedWith(const Path & statePath1, Path & statePath2);
PathSet toNonSharedPathSet(const PathSet & statePaths);
void revertToRevision(const Path & statePath, const unsigned int revision_arg, const bool recursive);

View file

@ -237,6 +237,9 @@ public:
/* TODO */
virtual void scanAndUpdateAllReferences(const Path & statePath, const bool recursive) = 0;
/* TODO */
virtual bool getSharedWith(const Path & statePath1, Path & statePath2) = 0;
/* TODO */
virtual PathSet toNonSharedPathSet(const PathSet & statePaths) = 0;

View file

@ -44,6 +44,7 @@ typedef enum {
wopQueryAvailableStateRevisions,
wopCommitStatePath,
wopScanAndUpdateAllReferences,
wopGetSharedWith,
wopToNonSharedPathSet,
wopRevertToRevision,
wopShareState,

View file

@ -566,7 +566,7 @@ static void installDerivations(Globals & globals,
//&& the identifiers are equal
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//TODO && (the users are equal || OR SHARED BETWEEN USERS)
//TODO && (the users are equal || OR SHARED BETWEEN USERS) isnt this already user specific?
//TODO
if( newSharedState == ""
&&
@ -621,7 +621,6 @@ static void installDerivations(Globals & globals,
store->shareState(i->second, i->first, false);
}
//**********************
//Let the stateDirs in /nix/state point to the solidStateDependencies

View file

@ -2,8 +2,41 @@ Usage: nix-state [OPTIONS...] [ARGUMENTS...]
`nix-state' is a tool to manipulate the Nix state-store and to run programs.
Operations:
Run Operations:
--run / -r: run and commit state
--commit-only: commit state
--run-only: run
--scan-only: scan for references
Run Options:
--scanreferences: set scan for references
--comment=...: Add a comment for commiting
Information:
--showstatepath: print the state path
--showderivations: print all derivations of this path
--showrevisions: show all revisions of the state path
--showsharedpaths: show where this path points to
--version: output version information
--help: display help
Share state Operations:
--unshare: unshare this path
--share-with a b: make the path a point to the path b
Share state Options:
--unshare-branch-state:
--unshare-restore-old-state:
Revert state Operations:
--revert-to-revision=x: revert to revision x
Revert state Options:
--revert-to-revision-recursively: revert recursively

File diff suppressed because one or more lines are too long

View file

@ -32,6 +32,8 @@ bool r_scanforReferences = false;
bool r_commit = true;
bool r_run = true;
bool revert_recursively = false;
bool unshare_branch = false;
bool unshare_restore_old = false;
/************************* Build time Functions ******************************/
@ -243,6 +245,36 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs)
}
static void opShowSharedPaths(Strings opFlags, Strings opArgs)
{
Path statePath = *(opArgs.begin());
if(!store->isValidStatePath(statePath))
throw UsageError(format("Path '%1%' is not a valid state path.") % statePath);
Path statePath1 = statePath;
Path statePath2;
bool isShared = false;
while(store->getSharedWith(statePath1, statePath2))
{
isShared = true;
printMsg(lvlError, format("Path '%1%' ---is shared with---> '%2%'") % statePath1 % statePath2);
statePath1 = statePath2;
}
if(!isShared)
printMsg(lvlError, format("Path '%1%' is not shared with another path") % statePath1);
}
static void opUnshare(Strings opFlags, Strings opArgs)
{
}
static void opShareWith(Strings opFlags, Strings opArgs)
{
}
static void opRunComponent(Strings opFlags, Strings opArgs)
{
@ -272,8 +304,15 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
string root_args = "";
for (Strings::iterator i = root_program_args.begin(); i != root_program_args.end(); ++i){
if(*i == "--help" || *i == "--version")
if(*i == "--help" || *i == "--version"){
printMsg(lvlError, format("Usage: try --statehelp for extended state help options"));
printMsg(lvlError, format("%1%") % padd("", '-', 54));
}
else if(*i == "--statehelp"){
printMsg(lvlError, format("%1%") % padd("", '-', 100));
printHelp();
}
//printMsg(lvlError, format("ARG %1%") % *i);
root_args += " \"" + *i + "\"";
@ -522,7 +561,6 @@ void run(Strings args)
Operation oldOp = op;
//Run options
if (arg == "--run" || arg == "-r") //run and commit
op = opRunComponent;
else if (arg == "--commit-only"){
@ -551,7 +589,6 @@ void run(Strings args)
//Info options
else if (arg == "--showstatepath")
op = opShowStatePath;
else if (arg == "--showderivations")
@ -560,17 +597,28 @@ void run(Strings args)
op = queryAvailableStateRevisions;
//State options
//Revering State options
else if (arg.substr(0,21) == "--revert-to-revision="){
op = revertToRevision;
bool succeed = string2UnsignedInt(arg.substr(21,arg.length()), revision_arg);
if(!succeed)
throw UsageError("The given revision is not a valid number");
}
else if (arg.substr(0,10) == "--revert-to-revision-recursively")
else if (arg == "--revert-to-revision-recursively")
revert_recursively = true;
//Shared state options
else if (arg == "--showsharedpaths")
op = opShowSharedPaths;
else if (arg == "--unshare")
op = opUnshare;
else if (arg == "--unshare-branch-state")
unshare_branch = true;
else if (arg == "--unshare-restore-old-state")
unshare_restore_old = true;
else if (arg == "--share-with")
op = opShareWith;
/*
--share-from

View file

@ -431,7 +431,7 @@ static void opRegisterSubstitutes(Strings opFlags, Strings opArgs)
Substitute sub;
PathSet references;
//TODO TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
//TODO TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PathSet stateReferences;
getline(cin, srcPath);

View file

@ -571,6 +571,17 @@ static void performOp(Source & from, Sink & to, unsigned int op)
break;
}
case wopGetSharedWith: {
Path statePath1 = readString(from);
Path statePath2;
startWork();
bool result = store->getSharedWith(statePath1, statePath2);
stopWork();
writeString(statePath2, to);
writeInt(result, to);
break;
}
case wopToNonSharedPathSet: {
PathSet statePaths = readStringSet(from);
startWork();