DIRECTORY BasicTime USING [GMT, nullGMT, Period], DFInternal USING [ AbortDF, CheckAbort, Client, ClientDescriptor, DefaultInteractionProc, DoAbort, GetFileInfo, LocalFileInfo, RemoteFileInfo, ReportFSError, ShortName, SimpleInteraction, YesOrNo], DFOperations USING [ AbortInteraction, DFInfoInteraction, FileAction, FileInteraction, InfoInteraction, InteractionProc, SModelAction], DFUtilities USING [ Date, DateFormat, DateToRope, DirectoryItem, FileItem, Filter, GetVersionNumber, ImportsItem, IncludeItem, ParseFromStream, ProcessItemProc, RemoveVersionNumber, SyntaxError, WriteItemToStream], FS USING [ Copy, Create, Delete, Error, GetInfo, GetName, OpenFile, OpenFileFromStream, Rename, StreamFromOpenFile, StreamOpen], FSExtras USING [NewCopy], IO USING [Close, GetIndex, PutFR, STREAM], Rope USING [Concat, Equal, Length, ROPE]; SModelImpl: CEDAR MONITOR IMPORTS BasicTime, DFInternal, DFUtilities, FS, FSExtras, IO, Rope EXPORTS DFOperations = BEGIN ROPE: TYPE = Rope.ROPE; nSModels: NAT _ 0; SModel: PUBLIC PROC [ dfFile: ROPE, action: DFOperations.SModelAction _ [], interact: DFOperations.InteractionProc _ NIL, clientData: REF ANY _ NIL, log: IO.STREAM _ NIL] RETURNS [errors, warnings, filesActedUpon: INT _ 0] = { client: DFInternal.Client = NEW[DFInternal.ClientDescriptor _ [ (interact _ IF interact = NIL THEN DFInternal.DefaultInteractionProc ELSE interact), clientData, log ]]; tempDF: ROPE = "SModelTemporaryDF$"; NewTemporaryDF: ENTRY PROC [pages: INT] RETURNS [out: IO.STREAM] = { outFile: FS.OpenFile; nSModels _ nSModels.SUCC; outFile _ FS.Create[ name: tempDF, pages: pages, setKeep: TRUE, keep: IF nSModels = 1 THEN 1 ELSE CARDINAL.LAST ! FS.Error => { localInfo: REF DFInternal.LocalFileInfo _ NEW[DFInternal.LocalFileInfo _ [name: tempDF]]; DFInternal.ReportFSError[error, localInfo, client, $abort]; } ]; RETURN[FS.StreamFromOpenFile[outFile, $write]] }; CloseTemporaryDF: PROC [out: IO.STREAM] RETURNS [tempName: ROPE] = { outFile: FS.OpenFile = FS.OpenFileFromStream[out]; tempName _ outFile.GetName[].fullFName; -- includes version number out.Close[]; }; FinishWithTemporaryDF: ENTRY PROC [ tempName: ROPE, localName: ROPE, commit: BOOL _ TRUE] = { IF commit THEN FS.Rename[from: tempName, to: localName] ELSE FS.Delete[tempName]; nSModels _ nSModels.PRED; }; UserConfirms: PROC [localInfo: REF DFInternal.LocalFileInfo, remoteInfo: REF DFInternal.RemoteFileInfo] RETURNS [BOOL] = { RETURN[DFInternal.YesOrNo[ client: client, message: IO.PutFR[ "%g {%g} to %g ?", [rope[DFUtilities.DateToRope[localInfo.date]]], [rope[DFUtilities.DateToRope[localInfo.date]]], [rope[DFUtilities.RemoveVersionNumber[remoteInfo.name]]], ], default: TRUE ]] }; SModelInner: PROC [dfFile: ROPE, date: DFUtilities.Date] RETURNS [REF DFInternal.RemoteFileInfo] = { directoryPath: ROPE _ NIL; somethingChanged: BOOL _ FALSE; dfRemoteInfo: REF DFInternal.RemoteFileInfo = NEW[DFInternal.RemoteFileInfo _ [name: dfFile, date: date]]; dfLocalInfo: REF DFInternal.LocalFileInfo = NEW[DFInternal.LocalFileInfo _ [name: DFInternal.ShortName[dfFile]]]; DoOneItem: DFUtilities.ProcessItemProc = { StoreThisFile: PROC [ localInfo: REF DFInternal.LocalFileInfo, remoteInfo: REF DFInternal.RemoteFileInfo, formatFromDF: DFUtilities.DateFormat] RETURNS [store: BOOL] = { lGMT: BasicTime.GMT = localInfo.date.gmt; -- can't be nullGMT rGMT: BasicTime.GMT = remoteInfo.date.gmt; -- may be nullGMT IF localInfo.attachedTo.Length[] = 0 THEN RETURN[TRUE]; IF ~Rope.Equal[ DFUtilities.RemoveVersionNumber[remoteInfo.name], DFUtilities.RemoveVersionNumber[localInfo.attachedTo], FALSE] THEN { IF remoteInfo.date = localInfo.date AND Rope.Equal[ DFInternal.ShortName[remoteInfo.name], DFInternal.ShortName[localInfo.attachedTo], FALSE] THEN { FS.Copy[ to: DFUtilities.RemoveVersionNumber[localInfo.name], from: remoteInfo.name, wantedCreatedTime: remoteInfo.date.gmt, remoteCheck: action.remoteCheck, attach: TRUE ! FS.Error => GO TO storeAnyway ]; localInfo.date.format _ $omitted ; -- force GetFileInfo to get the highest number version (that we just wrote) DFInternal.GetFileInfo[localInfo -- update attachedTo ! FS.Error => DFInternal.ReportFSError[error, localInfo, client, $abort] ]; RETURN[FALSE]; EXITS storeAnyway => NULL; }; RETURN[TRUE] }; SELECT formatFromDF FROM $explicit, $omitted => RETURN[lGMT ~= rGMT]; $notEqual => RETURN[action.remoteCheck AND lGMT ~= rGMT]; $greaterThan => SELECT TRUE FROM ~action.remoteCheck => RETURN[FALSE]; remoteInfo.date.format ~= $explicit => RETURN[TRUE]; -- no extant remote file ENDCASE => SELECT BasicTime.Period[from: lGMT, to: rGMT] FROM < 0 => RETURN[TRUE]; = 0 => RETURN[FALSE]; > 0 => { warnings _ warnings.SUCC; DFInternal.SimpleInteraction[ client, NEW[DFOperations.InfoInteraction _ [ class: $warning, message: IO.PutFR["%g {%g} is referenced with '>' in the DF file but is older than the remote version %g {%g}.", [rope[localInfo.name]], [rope[DFUtilities.DateToRope[localInfo.date]]], [rope[remoteInfo.name]], [rope[DFUtilities.DateToRope[remoteInfo.date]]] ] ]] ]; RETURN[FALSE] }; ENDCASE; ENDCASE; }; ReportMissing: PROC [localInfo: REF DFInternal.LocalFileInfo] = { warnings _ warnings.SUCC; DFInternal.SimpleInteraction[ client, NEW[DFOperations.InfoInteraction _ [ class: $warning, message: IO.PutFR["'%g' doesn't exist.", [rope[localInfo.name]]] ]] ]; }; SelfReference: PROC [shortName: ROPE] RETURNS [BOOL] = { RETURN[shortName.Equal[dfLocalInfo.name, FALSE]] }; DFInternal.CheckAbort[client]; WITH item SELECT FROM directory: REF DFUtilities.DirectoryItem => directoryPath _ directory.path1; file: REF DFUtilities.FileItem => { shortName: ROPE = DFUtilities.RemoveVersionNumber[file.name]; localInfo: REF DFInternal.LocalFileInfo _ NEW[DFInternal.LocalFileInfo _ [shortName]]; remoteInfo: REF DFInternal.RemoteFileInfo _ NEW[DFInternal.RemoteFileInfo _ [ name: directoryPath.Concat[file.name], date: file.date ]]; DFInternal.GetFileInfo[info: localInfo, remoteCheck: TRUE ! FS.Error => IF error.group = $user THEN {ReportMissing[localInfo]; GO TO skip} ELSE DFInternal.ReportFSError[error, localInfo, client, $abort] ]; IF action.remoteCheck THEN { remoteInfo.date _ localInfo.date; DFInternal.GetFileInfo[info: remoteInfo, notFoundOK: TRUE, client: client, errorLevel: $abort]; }; remoteInfo.name _ DFUtilities.RemoveVersionNumber[remoteInfo.name]; SELECT TRUE FROM SelfReference[shortName] => { remoteDFInfo: REF DFInternal.RemoteFileInfo = NEW[DFInternal.RemoteFileInfo _ [name: remoteInfo.name]]; DFInternal.GetFileInfo[ info: remoteDFInfo, notFoundOK: TRUE, client: client, errorLevel: $abort]; IF remoteDFInfo.date.gmt ~= BasicTime.nullGMT AND file.date.format = $explicit AND BasicTime.Period[from: file.date.gmt, to: remoteDFInfo.date.gmt] > 0 AND ~DFInternal.YesOrNo[ client: client, message: IO.PutFR[ "%g may be obsolete, since the remote version from which it is derived {%g} is older than %g {%g} (the present newest remote one); continue anyway?", [rope[shortName]], [rope[DFUtilities.DateToRope[file.date]]], [rope[remoteDFInfo.name]], [rope[DFUtilities.DateToRope[remoteDFInfo.date]]] ], default: FALSE, blunder: TRUE ] THEN DFInternal.DoAbort[client.log]; IF StoreThisFile[localInfo, remoteInfo, file.date.format] THEN somethingChanged _ TRUE; -- we'll actually store it later, if user approves. dfRemoteInfo.name _ remoteInfo.name; -- redundant unless top-level DF file.name _ shortName; -- ensure no version number SELECT file.date.format FROM $explicit, $omitted => file.date _ [$explicit, outFile.GetInfo[].created]; ENDCASE; }; StoreThisFile[localInfo, remoteInfo, file.date.format] AND UserConfirms[localInfo, remoteInfo] => { somethingChanged _ TRUE; IF action.storeChanged THEN { DFInternal.SimpleInteraction[ client, NEW[DFOperations.FileInteraction _ [ localFile: localInfo.name, remoteFile: remoteInfo.name, dateFormat: SELECT file.date.format FROM $explicit => $explicit, $greaterThan => $greaterThan, ENDCASE => $notEqual, date: localInfo.date.gmt, action: store ]] ]; file.name _ DFInternal.ShortName[ file: FSExtras.NewCopy[ to: remoteInfo.name, from: localInfo.name, attach: TRUE ! FS.Error => DFInternal.ReportFSError[error, remoteInfo, client, $abort]], keepVersion: TRUE ]; }; filesActedUpon _ filesActedUpon.SUCC; SELECT file.date.format FROM $explicit, $omitted => file.date _ localInfo.date; ENDCASE => file.name _ shortName; }; ENDCASE => IF localInfo.attachedTo.Length ~= 0 THEN { remoteVersion: ROPE = DFUtilities.GetVersionNumber[localInfo.attachedTo]; IF ~remoteVersion.Equal[DFUtilities.GetVersionNumber[file.name]] THEN { file.name _ shortName.Concat[remoteVersion]; somethingChanged _ TRUE; }; SELECT file.date.format FROM $omitted => { file.date _ localInfo.date; somethingChanged _ TRUE; }; $explicit => IF file.date ~= localInfo.date THEN { file.date _ localInfo.date; somethingChanged _ TRUE; }; ENDCASE; }; EXITS skip => NULL; }; include: REF DFUtilities.IncludeItem => { remoteInfo: REF DFInternal.RemoteFileInfo = SModelInner[include.path1, include.date]; IF ~Rope.Equal[remoteInfo.name, include.path1, FALSE] THEN { include.path1 _ remoteInfo.name; somethingChanged _ TRUE}; SELECT include.date.format FROM $explicit, $omitted => {include.date _ remoteInfo.date; somethingChanged _ TRUE}; ENDCASE => include.path1 _ DFUtilities.RemoveVersionNumber[include.path1]; }; imports: REF DFUtilities.ImportsItem => { localInfo: REF DFInternal.LocalFileInfo = NEW[DFInternal.LocalFileInfo _ [name: DFInternal.ShortName[imports.path1]]]; remoteInfo: REF DFInternal.RemoteFileInfo = NEW[DFInternal.RemoteFileInfo _ [name: imports.path1, date: imports.date]]; DFInternal.GetFileInfo[info: localInfo, remoteCheck: TRUE ! FS.Error => IF error.group = $user THEN {ReportMissing[localInfo]; GO TO skip} ELSE DFInternal.ReportFSError[error, localInfo, client, $abort] ]; IF action.remoteCheck THEN { DFInternal.GetFileInfo[info: remoteInfo, notFoundOK: TRUE, client: client, errorLevel: $abort]; IF StoreThisFile[localInfo, remoteInfo, imports.date.format] THEN { warnings _ warnings.SUCC; DFInternal.SimpleInteraction[ client, NEW[DFOperations.InfoInteraction _ [ class: $warning, message: IO.PutFR["%g {%g} doesn't correspond to %g {%g}.", [rope[localInfo.name]], [rope[DFUtilities.DateToRope[localInfo.date]]], [rope[remoteInfo.name]], [rope[DFUtilities.DateToRope[remoteInfo.date]]] ] ]] ]; }; imports.path1 _ remoteInfo.name; }; SELECT imports.date.format FROM $explicit => NULL; $omitted => {imports.date _ localInfo.date; somethingChanged _ TRUE}; ENDCASE => imports.path1 _ DFUtilities.RemoveVersionNumber[imports.path1]; EXITS skip => NULL; }; ENDCASE; DFUtilities.WriteItemToStream[out, item]; }; in: IO.STREAM = FS.StreamOpen[dfLocalInfo.name, $read ! FS.Error => DFInternal.ReportFSError[error, dfLocalInfo, client, $abort] ]; inFile: FS.OpenFile = FS.OpenFileFromStream[in]; out: IO.STREAM = NewTemporaryDF[inFile.GetInfo[].pages]; outFile: FS.OpenFile = FS.OpenFileFromStream[out]; dfLocalInfo.date _ [$explicit, inFile.GetInfo[].created]; DFInternal.SimpleInteraction[ client, NEW[DFOperations.DFInfoInteraction _ [action: start, dfFile: dfLocalInfo.name]] ]; DFUtilities.ParseFromStream[in, DoOneItem, DFUtilities.Filter[comments: TRUE] ! DFUtilities.SyntaxError -- [reason: ROPE]-- => DFInternal.DoAbort[ log, IO.PutFR["Syntax error in '%g'[%d]: %g", [rope[dfLocalInfo.name]], [cardinal[in.GetIndex[]]], [rope[reason]] ], interact, clientData ]; DFInternal.AbortDF => { in.Close[]; FinishWithTemporaryDF[CloseTemporaryDF[out], NIL, FALSE]; }; ]; in.Close[]; dfLocalInfo.date.gmt _ outFile.GetInfo[].created; IF somethingChanged AND UserConfirms[dfLocalInfo, dfRemoteInfo] THEN { tempName: ROPE = CloseTemporaryDF[out]; dfRemoteDateFormat: DFUtilities.DateFormat = dfRemoteInfo.date.format; dfRemoteInfo.date _ dfLocalInfo.date; IF action.storeChanged THEN { DFInternal.SimpleInteraction[ client, NEW[DFOperations.FileInteraction _ [ localFile: dfLocalInfo.name, remoteFile: dfRemoteInfo.name, dateFormat: SELECT dfRemoteDateFormat FROM $explicit => $explicit, $greaterThan => $greaterThan, ENDCASE => $notEqual, date: dfLocalInfo.date.gmt, action: $store ]] ]; [] _ FSExtras.NewCopy[to: dfRemoteInfo.name, from: tempName, attach: TRUE ! FS.Error => DFInternal.ReportFSError[error, dfRemoteInfo, client, $abort]]; FinishWithTemporaryDF[tempName, dfLocalInfo.name]; }; filesActedUpon _ filesActedUpon.SUCC; } ELSE FinishWithTemporaryDF[CloseTemporaryDF[out], NIL, FALSE]; DFInternal.SimpleInteraction[ client, NEW[DFOperations.DFInfoInteraction _ [ action: end, dfFile: dfLocalInfo.name, message: IF somethingChanged THEN NIL ELSE "DF file is unchanged" ]] ]; RETURN[dfRemoteInfo] }; [] _ SModelInner[dfFile, [] ! ABORTED => { DFInternal.SimpleInteraction[client, NEW[DFOperations.AbortInteraction _ [TRUE]]]; }; DFInternal.AbortDF => { errors _ errors.SUCC; DFInternal.SimpleInteraction[client, NEW[DFOperations.DFInfoInteraction _ [action: $abort, dfFile: dfFile]]]; CONTINUE }; ]; }; END. ¼SModelImpl.mesa Copyright c 1984 by Xerox Corporation. All rights reserved. Levin on December 19, 1983 4:20 pm Bob Hagmann on May 18, 1984 9:04:25 am PDT Russ Atkinson on September 10, 1984 12:38:28 pm PDT Global (monitored) variables Exported to DFOperations This procedure returns TRUE if, in principle, the file should be stored. It does not alter either 'localInfo' or 'remoteInfo' and does not let the user influence its decision. If the local file is not attached, we store it anyway, so that the attachment will be made. If the local file is attached to a remote file whose name differs from the one specified in the DF, we store it even if the dates match, so that the proper attachment will be made. If the short names of the two files are the same and they have the same date, we assume that the remote file is good enough. We need to make an attachment "the other way", however, and prevent the main loop from doing anything. The following tests need to be done delicately, since we may not know the actual truth about the remote file, but only what the DF file claims is true. In particular, it is quite possible that remoteDate.gmt = nullGMT when a remote file actually exists. (This case arises if formatFromDF ~= $explicit and ~action.remoteCheck.) The local file is known to exist. Any remote file with whose date matches will be satisfactory. Note that remoteInfo.name will typically have a version (hint). At this point, remoteInfo.date.format will be $explicit if we are supposed to believe that there is a remote file with create date remoteInfo.date.gmt, and remoteInfo.date.format will be $omitted if we are supposed to believe no such file exists. Furthermore, remoteInfo.name has no version number. This file item is a reference to the DF file we are updating. We check to see if the !H version on the remote server is newer than the input version of the DF file. If so, the user is warned, since he is probably using an obsolete DF file. If the file's date and/or (remote) version number is missing or incorrect, we may wish to update them/it. Because of the logic on the earlier call of GetFileInfo, the local file is known to exist. However, it may or may not be attached to a remote file, since the user may have explicitly prohibited a Copy in the preceding arm of the SELECT. If it isn't attached, we don't want to disturb the DF file entry. We would like to RESUME at this point, but until ABORTED is redeclared as a SIGNAL, it won't work. Ê ˜šœ™Jšœ Ïmœ1™šœžœ ˜Jšœ žœžœ,˜YJšœ;˜;J˜——J˜—Jšžœžœ%˜.Jšœ˜—š Ÿœžœžœžœžœ žœ˜DJšœ žœ žœ˜2JšœžœÏc˜CJ˜ Jšœ˜—šŸœžœžœ˜#Jš œ žœ žœ žœžœ˜9Jšžœžœžœ&˜7Jšžœ˜Jšœžœ˜Jšœ˜—šŸ œžœ žœ'žœ˜gJšžœžœ˜šžœ˜Jšœ˜šœ ˜ šžœ˜ Jšœ˜Jšœ/˜/Jšœ/˜/Jšœ9˜9Jšœ˜——Jšœ ž˜ Jšœ˜—J˜—š Ÿ œžœ žœžœžœ˜dJšœžœžœ˜Jšœžœžœ˜Jšœžœžœ9˜jJšœ žœžœB˜qšœ*˜*šŸ œžœ˜Jšœ žœ'žœ˜SJšœ%˜%Jšžœ žœ˜Jšœ°™°Jšœžœ ˜>Jšœžœ ˜=Jšœ[™[Jšžœ#žœžœžœ˜7Jšœ´™´šžœ ˜Jšœ1˜1Jšœ6˜6šžœžœ˜ Jšœä™äšžœ"žœ ˜3Jšœ&˜&Jšœ+˜+šžœžœ˜ šžœ˜Jšœ4˜4Jšœ>˜>Jšœ ˜ Jšœž˜ Jšœžœ žœžœ ˜Jšœ˜—Jšœ$ K˜ošœ" ˜6JšœžœD˜HJ˜—Jšžœžœ˜šž˜Jšœžœ˜—J˜——Jšžœžœ˜ J˜——Jšœ€žœÆ™Èšžœž˜Jšœžœ˜,Jšœ žœžœ˜9šœ˜šžœžœž˜Jšœžœžœ˜%Jšœ'žœžœ ˜Nšžœ˜ šžœ(ž˜2Jšœžœžœ˜Jšœžœžœ˜šœ˜Jšœžœ˜šœ˜Jšœ˜šžœ!˜$J˜šœ žœe˜pJšœ˜Jšœ/˜/Jšœ˜Jšœ/˜/J˜—J˜—Jšœ˜—Jšžœžœ˜ J˜—Jšžœ˜————Jšžœ˜—J˜—šŸ œžœ žœ˜AJšœžœ˜šœ˜Jšœ˜šžœ!˜$J˜Jšœ žœžœ˜@J˜—Jšœ˜—J˜—š Ÿ œžœ žœžœžœ˜8Jšžœ#žœ˜1J˜—Jšœ˜šžœžœžœ˜šœ žœ˜+Jšœ ˜ —šœžœ˜#Jšœ žœ.˜=Jšœ žœžœ)˜Všœ žœ˜+šžœ˜!Jšœ&˜&Jšœ˜Jšœ˜——šœ5ž˜9šœžœ ˜ Jšžœžœžœžœ˜BJšžœ;˜?—Jšœ˜—šžœžœ˜Jšœ¡™¡Jšœ!˜!Jšœ5žœ&˜_J˜—JšœC˜CJšœ«™«šžœžœž˜šœ˜Jšœñ™ñšœžœ˜-Jšžœ6˜9—šœ˜Jšœ žœ&˜J—šžœ,ž˜1Jšœž˜ JšœEž˜Hšœ˜Jšœ˜šœ ˜ šžœ˜ Jšœ•˜•Jšœ˜Jšœ*˜*Jšœ˜Jšœ1˜1Jšœ˜——Jšœ ž˜Jšœ ž˜ Jšœžœ ˜&——šžœ8ž˜>Jšœžœ 3˜M—Jšœ&  ˜FJšœ ˜3šžœž˜JšœJ˜JJšžœ˜—J˜—Jšœ7ž˜:šœ(˜(Jšœžœ˜šžœžœ˜šœ˜J˜šžœ!˜$Jšœ˜Jšœ˜šœ ˜ šžœž˜Jšœ˜Jšœ˜Jšžœ˜——Jšœ˜J˜ Jšœ˜—J˜—šœ!˜!šœ˜Jšœ3ž˜7JšœžœG˜K—Jšœ ž˜J˜—J˜—Jšœ žœ˜%šžœž˜Jšœ2˜2Jšžœ˜!—J˜—šžœ˜ JšœÑžœ6žœ ™›šžœ"žœ˜*Jšœžœ6˜Išžœ?žœ˜GJšœ,˜,Jšœžœ˜J˜—šžœž˜šœ ˜ Jšœ˜Jšœžœ˜Jšœ˜—šœ ˜ šžœžœ˜%Jšœ˜Jšœžœ˜Jšœ˜——Jšžœ˜—J˜———šž˜Jšœžœ˜ —J˜—šœ žœ˜)Jšœ žœF˜Ušžœ-žœžœ˜šœ˜Jšœ˜šžœ#˜&Jšœ ˜ Jšœ˜Jš œ žœžœžœžœ˜AJšœ˜—Jšœ˜—Jšžœ˜J˜—šœ˜šžœ˜ Jšœ%žœ"žœ˜RJšœžœžœžœ™bJšœ˜—šœ˜Jšœžœ˜Jšœ$žœE˜mJšž˜J˜—J˜—J˜—J˜Jšžœ˜—…—2~KC