mirror of
https://github.com/NixOS/nix.git
synced 2025-11-27 12:41:00 +01:00
Implemented runtime --share= and --unshare options. Fixed some things.
This commit is contained in:
parent
86f0fd8341
commit
d0458acb7c
14 changed files with 90 additions and 54 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue