RollbackAndAnything.Mesa
Last Edited by: Spreitzer, May 24, 1985 1:48:55 pm PDT
Mike Spreitzer November 3, 1986 11:11:03 pm PST
DIRECTORY Booting, Commander, CommandTool, FS, IO, List, MessageWindow, ProcessProps, Rope, UserCredentials, ViewerClasses, ViewerOps;
RollbackAndAnything: CEDAR MONITOR
IMPORTS Booting, Commander, CommandTool, FS, IO, List, MessageWindow, ProcessProps, Rope, UserCredentials, ViewerOps
=
BEGIN
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
enabled: BOOLTRUE;
Able: ENTRY PROC RETURNS [able: BOOL] = {
able ← enabled;
enabled ← FALSE};
AnythingWork: PROC [ctv: Viewer] = {
looking: BOOL;
from: IO.STREAMNIL;
cmd: ROPE;
sourceFileName: ROPE ← CmdFileName[];
copyFileName: ROPE ← CopyFileName[];
FindOne: PROC [v: Viewer] RETURNS [BOOLTRUE] --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 ANYNIL, msg: ROPENIL] --Commander.CommandProc-- =
{AnythingWork[CommandTool.GetViewer[cmd]]};
RollbackAnd: PROC [cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL] --Commander.CommandProc-- = {
to: IO.STREAM = FS.StreamOpen[CmdFileName[], create];
wDir: REF ANY = List.Assoc[$WorkingDirectory, ProcessProps.GetPropList[]];
IF wDir # NIL THEN {
WITH wDir SELECT FROM
x: ROPE => to.PutF["cd %g; ", [rope[x]]];
x: REF TEXT => to.PutF["cd %g; ", [text[x]]];
ENDCASE => to.PutF["abort because wDir (%g) isn't a ROPE or REF TEXT; ", [refAny[wDir]]];
}
ELSE to.PutRope["cdr; "];
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", interpreted: FALSE];
END.