RollbackAndAnything:
CEDAR
MONITOR
IMPORTS Booting, Commander, CommandExtras, CommandTool, CommandToolExtras,
FS,
IO, MessageWindow, Rope, UserCredentials, ViewerOps = {
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
enabled: BOOL ← TRUE;
Able:
ENTRY
PROC
RETURNS [able:
BOOL] = {
able ← enabled;
enabled ← FALSE};
AnythingWork:
PROC [ctv: Viewer] = {
looking: BOOL;
from: IO.STREAM ← NIL;
cmd: ROPE;
sourceFileName: ROPE ← CmdFileName[];
copyFileName: ROPE ← CopyFileName[];
FindOne:
PROC [v: Viewer]
RETURNS [
BOOL ←
TRUE]
--ViewerOps.EnumProc-- =
BEGIN
IF v.name.Find["CommandTool: "] = 0
AND v.class.flavor = $Typescript
THEN {ctv ← v; looking ← FALSE};
RETURN [looking];
END;
IF NOT Able[] THEN RETURN;
from ← FS.StreamOpen[sourceFileName !FS.Error => {from ← NIL; CONTINUE}];
IF from = NIL THEN RETURN;
cmd ← from.GetTokenRope[AllOther].token;
from.Close[];
FS.Rename[from: sourceFileName, to: copyFileName];
IF cmd.Length[] = 0 THEN RETURN;
looking ← ctv = NIL OR ctv.destroyed;
IF looking THEN ViewerOps.EnumerateViewers[FindOne];
IF looking THEN MessageWindow.Append[" RollbackAndAnything couldn't find a CommandTool"]
ELSE ctv.class.notify[ctv, LIST[cmd]];
};
AllOther:
PROC [char:
CHAR]
RETURNS [cc:
IO.CharClass]
--IO.BreakProc-- =
{cc ← other};
CmdFileName:
PROC
RETURNS [fileName:
ROPE] = {
userName: ROPE ← UserCredentials.Get[].name;
fileName ← Rope.Cat["///Users/", userName, "/ToDoWhenRollback"]};
CopyFileName:
PROC
RETURNS [fileName:
ROPE] = {
userName: ROPE ← UserCredentials.Get[].name;
fileName ← Rope.Cat["///Users/", userName, "/DidWhenRollbacked"]};
UponRollback:
PROC [clientData:
REF
ANY]
--Booting.RollbackProc-- =
{AnythingWork[NIL]};
DoRollbackStuff:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ←
NIL, msg:
ROPE ←
NIL]
--Commander.CommandProc-- =
{AnythingWork[CommandToolExtras.GetViewer[cmd]]};
RollbackAnd:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ←
NIL, msg:
ROPE ←
NIL]
--Commander.CommandProc-- = {
to: IO.STREAM ← FS.StreamOpen[CmdFileName[], create];
to.PutRope[cmd.commandLine];
to.Close[];
Copied from CommandToolFix.InitialCommandsImpl.Rollback:
RETURN[$Failure, Booting.Boot[[self[]], [r: TRUE]]];
};
Booting.RegisterProcs[r: UponRollback];
Commander.Register[key: "DoRollbackStuff", proc: DoRollbackStuff, doc: "Execute commands saved for execution upon rollback"];
Commander.Register[key: "RollbackAnd", proc: RollbackAnd, doc: "Rollback, then execute rest of command line"];
CommandExtras.MakeUninterpreted[Commander.Lookup[CommandTool.CurrentWorkingDirectory[].Cat["RollbackAnd"]]];
}.