diff --git a/install_full.sh b/install_full.sh index 79878fd6b..e51a96a5d 100755 --- a/install_full.sh +++ b/install_full.sh @@ -48,7 +48,7 @@ fi --prefix=$nixstatepath \ --with-store-dir=/nix/store \ --with-store-state-dir=/nix/state \ - --with-ext3cow-header=/nix/store/8nirllv1w6qv6c5srjgah2m82bfi1d6k-linux-2.6.21.5/lib/modules/2.6.21.5-default/build/include/linux/ext3cow_fs.h \ + --with-ext3cow-header=/nix/store/v95qf520d6972pshykrah1dz3z53rkmj-linux-2.6.21.7/lib/modules/2.6.21.7-default/build/include/linux/ext3cow_fs.h \ --localstatedir=/nix/var diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index ec95f729d..84080839a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1726,7 +1726,7 @@ bool querySolidStateReferencesTxn(const Transaction & txn, const Path & statePat return notempty; } -void unShareStateTxn(const Transaction & txn, const Path & path, const bool copyFromOld) +void unShareStateTxn(const Transaction & txn, const Path & path, const bool branch, const bool restoreOld) //TODO ADD BOOL YES/NO TO RESTORE OLD STATE (LAST REV.) { //Check if is statePath if(!isValidStatePathTxn(txn, path)) @@ -1739,24 +1739,32 @@ void unShareStateTxn(const Transaction & txn, const Path & path, const bool copy //Remove Symlink removeSymlink(path); + + //Remove earlier entries (unshare) (we must do this before revertToRevisionTxn) + nixDB.delPair(txn, dbSharedState, path); //Touch dir with correct rights Derivation drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, path)); ensureStateDir(path, drv.stateOutputs.find("state")->second.username, "nixbld", "700"); - //Copy if necessary (TODO first snapshot?) - if(copyFromOld){ + if(branch && restoreOld) + throw Error(format("You cannot branch and restore the old state at the same time for path: '%1%' ") % path); + + //Copy if necessary + if(branch){ copyContents(sharedWithOldPath, path); } - //Remove earlier entries (unshare) - nixDB.delPair(txn, dbSharedState, path); + //Restore the latest snapshot (non-recursive) made on this statepath + if(restoreOld){ + revertToRevisionTxn(txn, path, 0, false); + } } -void LocalStore::unShareState(const Path & path, const bool copyFromOld) +void LocalStore::unShareState(const Path & path, const bool branch, const bool restoreOld) { Transaction txn(nixDB); - unShareStateTxn(txn, path, copyFromOld); + unShareStateTxn(txn, path, branch, restoreOld); txn.commit(); } @@ -1799,7 +1807,7 @@ void shareStateTxn(const Transaction & txn, const Path & from, const Path & to, //If from was shared: unshare Path empty; if(querySharedStateTxn(txn, from, empty)) - unShareStateTxn(txn, from, false); + unShareStateTxn(txn, from, false, false); //Remove state path and link deletePathWrapped(from); diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 33f1aecf3..b32973e33 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -118,7 +118,7 @@ public: void shareState(const Path & from, const Path & to, const bool snapshot); - void unShareState(const Path & path, const bool copyFromOld); + void unShareState(const Path & path, const bool branch, const bool restoreOld); }; @@ -246,7 +246,7 @@ void setSolidStateReferencesTxn(const Transaction & txn, const Path & statePath, bool querySolidStateReferencesTxn(const Transaction & txn, const Path & statePath, PathSet & paths); void shareStateTxn(const Transaction & txn, const Path & from, const Path & to, const bool snapshot); -void unShareStateTxn(const Transaction & txn, const Path & path, const bool copyFromOld); +void unShareStateTxn(const Transaction & txn, const Path & path, const bool branch, const bool restoreOld); PathSet toNonSharedPathSetTxn(const Transaction & txn, const PathSet & statePaths); Path toNonSharedPathTxn(const Transaction & txn, const Path & statePath); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index dc2cd14f3..c98eea6b7 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -540,11 +540,12 @@ void RemoteStore::shareState(const Path & from_arg, const Path & to_arg, const b readInt(from); } -void RemoteStore::unShareState(const Path & path, const bool copyFromOld) +void RemoteStore::unShareState(const Path & path, const bool branch, const bool restoreOld) { writeInt(wopUnShareState, to); writeString(path, to); - writeInt(copyFromOld ? 1 : 0, to); + writeInt(branch ? 1 : 0, to); + writeInt(restoreOld ? 1 : 0, to); processStderr(); readInt(from); } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index d67b843a6..ecaef0f3c 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -104,7 +104,7 @@ public: void shareState(const Path & from, const Path & to, const bool snapshot); - void unShareState(const Path & path, const bool copyFromOld); + void unShareState(const Path & path, const bool branch, const bool restoreOld); private: AutoCloseFD fdSocket; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index f699988d7..b203fd315 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -250,7 +250,7 @@ public: virtual void shareState(const Path & from, const Path & to, const bool snapshot) = 0; /* TODO */ - virtual void unShareState(const Path & path, const bool copyFromOld) = 0; + virtual void unShareState(const Path & path, const bool branch, const bool restoreOld) = 0; }; diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index fcde47495..06fbca93a 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -108,6 +108,12 @@ void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const RevisionClosureTS getTimestamps; queryStateRevisionsTxn(txn, statePath_ns, getRivisions, getTimestamps, revision_arg); + //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //include recursive + //lookup 0 (latest) to the real revision + + + //Revert each statePath in the list for (RevisionClosure::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){ Path statePath = (*i).first; @@ -180,7 +186,7 @@ void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const } - //*** Now also revert state references to the specific revision (the revision is already converted to a timestamp here) + //*** Now also revert _state references_ to the specific revision (the revision is already converted to a timestamp here) //Query the references of the old revision (already converted to a timestamp) PathSet state_references; diff --git a/src/libstore/store-state.hh b/src/libstore/store-state.hh index eaabd4e23..ea7a24afc 100644 --- a/src/libstore/store-state.hh +++ b/src/libstore/store-state.hh @@ -25,6 +25,7 @@ namespace nix { void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path & statePath); + /* revision 0 == latest ????? */ void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const int revision_arg, const bool recursive); @@ -54,7 +55,7 @@ namespace nix { bool queryStateReferences(Database & nixDB, const Transaction & txn, TableId references_table, TableId revisions_table, const Path & statePath, Strings & references, const unsigned int revision = 0, const unsigned int timestamp = 0); - /* Set the revision number of the statePath and the revision numbers of all state paths in the references closure */ + /* Get the revision number of the statePath and the revision numbers of all state paths in the references closure */ void setStateRevisions(Database & nixDB, const Transaction & txn, TableId revisions_table, TableId revisions_comments, TableId snapshots_table, const RevisionClosure & revisions, const Path & rootStatePath, const string & comment); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 38bc7f1ca..db9d7c000 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1295,15 +1295,15 @@ void symlinkPath(const Path & existingDir, const Path & newLinkName) //TODO bool */ runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-ln"); - executeShellCommand("whoami"); - executeShellCommand("pwd"); + //executeShellCommand("whoami"); + //executeShellCommand("pwd"); printMsg(lvlError, format("ln -sf %1% %2%") % existingDir % newLinkName); } void removeSymlink(const string & path) { - if(path[path.length() - 1] != '/') - throw Error(format("We dont want to remove the enitre directory, only the symlink, but a / is given for `%1%'") % path); + if(path[path.length() - 1] == '/') + throw Error(format("We dont want to remove the symlink, not the enitre directory, but a / is given for `%1%'") % path); deletePath(path); } @@ -1316,8 +1316,6 @@ void ensureStateDir(const Path & statePath, const string & user, const string & void copyContents(const Path & from, const Path & to) //TODO bool shellexpansion, bool failure for nix-env { - //executeShellCommand("whoami"); - //TODO Could be a symlink (to a non-existing dir) /* if(!DirectoryExist(from)) @@ -1326,33 +1324,21 @@ void copyContents(const Path & from, const Path & to) //TODO bool shellexpansion throw Error(format("Path `%1%' doenst exist ...") % to); */ - //executeShellCommand("ls -l "+from); - //executeShellCommand("ls -l "+from+"/"); - //executeShellCommand("ls -l "+to); - //executeShellCommand("ls -l "+to+"/"); - + //TODO do a Rsync instead of a cp. + //rsync -avHx --delete from to + //Copy all files + dirs recursively Strings p_args; p_args.push_back("-c"); //we call the shell (/bin/sh -c) so it expands the * to all files p_args.push_back("cp -R "+from + "/* "+to); - /* - p_args.push_back("cp"); - p_args.push_back("-R"); - p_args.push_back(from + "/*"); - p_args.push_back(to); - */ runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp"); //Also copy the hidden files (but not the ../ dir) p_args.empty(); p_args.push_back("-c"); p_args.push_back("cp " + from + "/.[a-zA-Z0-9]* " +to); - /* - p_args.push_back(cp"); - p_args.push_back(from + "/.[a-zA-Z0-9]*"); - p_args.push_back(to); - */ runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp"); + } } diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index cde585980..8e4372ac3 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -639,7 +639,7 @@ static void installDerivations(Globals & globals, PathSet comparePaths; comparePaths.insert(statePath); comparePaths.insert(read_statePath); - if(store->toNonSharedPathSet(comparePaths).size() != 1) //TODO !!!!!!!!!!!!! only copy when not already a symlink to a statePath !!!!!!!!! + if(store->toNonSharedPathSet(comparePaths).size() != 1) //TODO !!!!!!!!!!!!!?? copyContents(externalState, statePath); } else diff --git a/src/nix-state/help.txt b/src/nix-state/help.txt index 6ebac0386..39fd6c9da 100644 --- a/src/nix-state/help.txt +++ b/src/nix-state/help.txt @@ -1,4 +1,4 @@ -Usage: nix-state [OPTIONS...] [ARGUMENTS...] +Usage: nix-state [OPTIONS...] [ARGUMENTS...] [NIX Store/State-Path] `nix-state' is a tool to manipulate the Nix state-store and to run programs. @@ -26,12 +26,13 @@ Information: Share state Operations: --unshare: unshare this path - --share-with a b: make the path a point to the path b + --share-with=a b: make the statepath b point to a + --copy-from=a b: make the contents of statepath b equal to the contents of a Share state Options: - --unshare-branch-state: - --unshare-restore-old-state: + --unshare-and-branch-state: + --unshare-and-restore-old-state: (default) Revert state Operations: diff --git a/src/nix-state/help.txt.hh b/src/nix-state/help.txt.hh index 29e347057..6eef7966e 100644 --- a/src/nix-state/help.txt.hh +++ b/src/nix-state/help.txt.hh @@ -1 +1 @@ -static unsigned char helpText[] = {0x55, 0x73, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x6e, 0x69, 0x78, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x5b, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x2e, 0x2e, 0x2e, 0x5d, 0x20, 0x5b, 0x41, 0x52, 0x47, 0x55, 0x4d, 0x45, 0x4e, 0x54, 0x53, 0x2e, 0x2e, 0x2e, 0x5d, 0x0a, 0x0a, 0x60, 0x6e, 0x69, 0x78, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x6f, 0x6f, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6e, 0x69, 0x70, 0x75, 0x6c, 0x61, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4e, 0x69, 0x78, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2d, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x73, 0x2e, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x75, 0x6e, 0x20, 0x2f, 0x20, 0x2d, 0x72, 0x3a, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x3a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x75, 0x6e, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x3a, 0x20, 0x72, 0x75, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x63, 0x61, 0x6e, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x3a, 0x20, 0x73, 0x63, 0x61, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x20, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x09, 0x09, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x63, 0x61, 0x6e, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x3a, 0x20, 0x73, 0x65, 0x74, 0x20, 0x73, 0x63, 0x61, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x3d, 0x2e, 0x2e, 0x2e, 0x3a, 0x20, 0x41, 0x64, 0x64, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x20, 0x0a, 0x0a, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x73, 0x74, 0x61, 0x74, 0x65, 0x70, 0x61, 0x74, 0x68, 0x3a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x64, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x64, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x20, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x70, 0x61, 0x74, 0x68, 0x73, 0x3a, 0x20, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x74, 0x68, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x68, 0x65, 0x6c, 0x70, 0x3a, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x68, 0x65, 0x6c, 0x70, 0x0a, 0x0a, 0x53, 0x68, 0x61, 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x3a, 0x20, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2d, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, 0x62, 0x3a, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x74, 0x68, 0x20, 0x61, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x61, 0x74, 0x68, 0x20, 0x62, 0x0a, 0x0a, 0x53, 0x68, 0x61, 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2d, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3a, 0x20, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2d, 0x72, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2d, 0x6f, 0x6c, 0x64, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3a, 0x20, 0x0a, 0x20, 0x0a, 0x52, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x2d, 0x74, 0x6f, 0x2d, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x78, 0x3a, 0x20, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x78, 0x0a, 0x0a, 0x52, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x2d, 0x74, 0x6f, 0x2d, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x2d, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x6c, 0x79, 0x3a, 0x20, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x6c, 0x79, 0x0a, }; +static unsigned char helpText[] = {0x55, 0x73, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x6e, 0x69, 0x78, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x5b, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x2e, 0x2e, 0x2e, 0x5d, 0x20, 0x5b, 0x41, 0x52, 0x47, 0x55, 0x4d, 0x45, 0x4e, 0x54, 0x53, 0x2e, 0x2e, 0x2e, 0x5d, 0x20, 0x5b, 0x4e, 0x49, 0x58, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2d, 0x50, 0x61, 0x74, 0x68, 0x5d, 0x0a, 0x0a, 0x60, 0x6e, 0x69, 0x78, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x27, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x6f, 0x6f, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x6d, 0x61, 0x6e, 0x69, 0x70, 0x75, 0x6c, 0x61, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4e, 0x69, 0x78, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2d, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x73, 0x2e, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x75, 0x6e, 0x20, 0x2f, 0x20, 0x2d, 0x72, 0x3a, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x3a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x75, 0x6e, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x3a, 0x20, 0x72, 0x75, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x63, 0x61, 0x6e, 0x2d, 0x6f, 0x6e, 0x6c, 0x79, 0x3a, 0x20, 0x73, 0x63, 0x61, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x20, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x09, 0x09, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x63, 0x61, 0x6e, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x3a, 0x20, 0x73, 0x65, 0x74, 0x20, 0x73, 0x63, 0x61, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x3d, 0x2e, 0x2e, 0x2e, 0x3a, 0x20, 0x41, 0x64, 0x64, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x20, 0x0a, 0x0a, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x73, 0x74, 0x61, 0x74, 0x65, 0x70, 0x61, 0x74, 0x68, 0x3a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x64, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x64, 0x65, 0x72, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x20, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x6f, 0x77, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x70, 0x61, 0x74, 0x68, 0x73, 0x3a, 0x20, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x74, 0x68, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x68, 0x65, 0x6c, 0x70, 0x3a, 0x20, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x68, 0x65, 0x6c, 0x70, 0x0a, 0x0a, 0x53, 0x68, 0x61, 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x3a, 0x20, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x74, 0x68, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2d, 0x77, 0x69, 0x74, 0x68, 0x3d, 0x61, 0x20, 0x62, 0x3a, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x70, 0x61, 0x74, 0x68, 0x20, 0x62, 0x20, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x63, 0x6f, 0x70, 0x79, 0x2d, 0x66, 0x72, 0x6f, 0x6d, 0x3d, 0x61, 0x20, 0x62, 0x3a, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x70, 0x61, 0x74, 0x68, 0x20, 0x62, 0x20, 0x65, 0x71, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x0a, 0x0a, 0x53, 0x68, 0x61, 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2d, 0x61, 0x6e, 0x64, 0x2d, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3a, 0x20, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x75, 0x6e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2d, 0x61, 0x6e, 0x64, 0x2d, 0x72, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2d, 0x6f, 0x6c, 0x64, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3a, 0x20, 0x28, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x29, 0x0a, 0x20, 0x0a, 0x52, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x2d, 0x74, 0x6f, 0x2d, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x78, 0x3a, 0x20, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x78, 0x0a, 0x0a, 0x52, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a, 0x0a, 0x20, 0x20, 0x2d, 0x2d, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x2d, 0x74, 0x6f, 0x2d, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x2d, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x6c, 0x79, 0x3a, 0x20, 0x72, 0x65, 0x76, 0x65, 0x72, 0x74, 0x20, 0x72, 0x65, 0x63, 0x75, 0x72, 0x73, 0x69, 0x76, 0x65, 0x6c, 0x79, 0x0a, }; diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index 00befb756..01ac81210 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -33,7 +33,9 @@ bool r_commit = true; bool r_run = true; bool revert_recursively = false; bool unshare_branch = false; -bool unshare_restore_old = false; +bool unshare_restoreOld = true; +string share_with; +string copy_from; /************************* Build time Functions ******************************/ @@ -267,12 +269,27 @@ static void opShowSharedPaths(Strings opFlags, Strings opArgs) static void opUnshare(Strings opFlags, Strings opArgs) { + Path statePath = *(opArgs.begin()); + if(!store->isValidStatePath(statePath)) + throw UsageError(format("Path '%1%' is not a valid state path.") % statePath); + store->unShareState(statePath, unshare_branch, unshare_restoreOld); } static void opShareWith(Strings opFlags, Strings opArgs) { + Path statePath = *(opArgs.begin()); + if(!store->isValidStatePath(statePath)) + throw UsageError(format("Path '%1%' is not a valid state path.") % statePath); + store->shareState(statePath, share_with, false); +} + +static void opCopyFrom(Strings opFlags, Strings opArgs) +{ + //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //copy_from + throw UsageError(format("TODO !!!!!!!!!!!!")); } @@ -307,10 +324,14 @@ static void opRunComponent(Strings opFlags, Strings opArgs) if(*i == "--help" || *i == "--version"){ printMsg(lvlError, format("Usage: try --statehelp for extended state help options")); printMsg(lvlError, format("%1%") % padd("", '-', 54)); + r_scanforReferences = false; + r_commit = false; } else if(*i == "--statehelp"){ printMsg(lvlError, format("%1%") % padd("", '-', 100)); printHelp(); + r_scanforReferences = false; + r_commit = false; } //printMsg(lvlError, format("ARG %1%") % *i); @@ -555,6 +576,11 @@ void run(Strings args) /* test */ + if(args.size() == 1 && ( *(args.begin()) == "--help" || *(args.begin()) == "--statehelp")){ + printHelp(); + return; + } + for (Strings::iterator i = args.begin(); i != args.end(); ) { string arg = *i++; @@ -612,17 +638,23 @@ void run(Strings args) op = opShowSharedPaths; else if (arg == "--unshare") op = opUnshare; - else if (arg == "--unshare-branch-state") + else if (arg == "--unshare-and-branch-state") unshare_branch = true; - else if (arg == "--unshare-restore-old-state") - unshare_restore_old = true; - else if (arg == "--share-with") + else if (arg == "--unshare-and-restore-old-state") //default true + unshare_restoreOld = true; + else if (arg.substr(0,13) == "--share-with="){ op = opShareWith; + share_with = arg.substr(13,arg.length()); + } + else if (arg.substr(0,12) == "--copy-from="){ + op = opCopyFrom; + copy_from = arg.substr(12,arg.length()); + } /* - --share-from - --unshare + --copy-from + */ diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index a0d51c052..674659a64 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -615,9 +615,10 @@ static void performOp(Source & from, Sink & to, unsigned int op) case wopUnShareState: { Path path = readString(from); - bool copyFromOld = readInt(from) == 1; + bool branch = readInt(from) == 1; + bool restoreOld = readInt(from) == 1; startWork(); - store->unShareState(path, copyFromOld); + store->unShareState(path, branch, restoreOld); stopWork(); writeInt(1, to); break;