<> <> DIRECTORY Booting, Commander, CommandExtras, CommandTool, CommandToolExtras, FS, IO, MessageWindow, Rope, UserCredentials, ViewerClasses, ViewerOps; 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[]; <> 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"]]]; }.