-- File: AlpineConvertImpl.mesa
-- Last edited by:
-- Kolling on February 9, 1984 2:49:52 pm PST


DIRECTORY
AlpFile
USING[Handle, Open, ReadProperties],
AlpineEnvironment
USING[AccessList, FileStore, LockOption,
nullVolumeGroupID, OwnerProperty, OwnerPropertyValuePair, Outcome, PageCount,
PropertyValuePair, UniversalFile],
AlpineInterimDirectory
USING[EnumerateDirectoryUnderTrans],
AlpInstance
USING[Create, Handle],
AlpTransaction
USING[AssertAlpineWheel, Create, Finish, GetNextVolumeGroup, Handle, ReadNextOwner],
Convert
USING[RopeFromInt],
FS
USING[StreamOpen],
IO
USING[Close, PutFR, PutRope, STREAM, text],
RuntimeError
USING[BoundsFault],
Rope
USING[Cat, Equal, Find, ROPE, Substr];

AlpineConvertImpl: CEDAR PROGRAM
IMPORTS AlpF: AlpFile, AlpineInterimDirectory, AlpI: AlpInstance, AlpT: AlpTransaction,
Convert, FS, IO, Rope, RuntimeError

= BEGIN OPEN AE: AlpineEnvironment;



Main: PUBLIC PROC =
BEGIN
createOwnersFile: IO.STREAMFS.StreamOpen["CreateOwners.cm", $create];
saveAndRestoreFile: IO.STREAMFS.StreamOpen["SaveAndRestoreFiles.cm", $create];
setFilePropsFile: IO.STREAMFS.StreamOpen["SetFileProps.cm", $create];
alpOwner: Rope.ROPENIL;
transHandle: AlpT.Handle ← AlpT.Create[instHandle: AlpI.Create[fileStore: "luther.alpine"],
createLocalWorker: TRUE];
transHandle.AssertAlpineWheel[TRUE];
DO
ownerProperties: LIST OF AE.OwnerPropertyValuePair;
ownerCreateAccessList: AE.AccessList;
ownerModifyAccessList: AE.AccessList;
ownerQuota: INT;
directory: Rope.ROPE;
[alpOwner, ownerProperties] ← transHandle.ReadNextOwner[
volumeGroupID: transHandle.GetNextVolumeGroup[previousGroup:
AE.nullVolumeGroupID, lock: [none, wait]], previousOwner: alpOwner, desiredProperties:
ALL [TRUE]];
IF alpOwner = NIL THEN EXIT;
IF Rope.Equal[alpOwner, "SpecialOwnerForAlpineAdmin", FALSE] THEN LOOP;
directory ← Rope.Cat["[luther.alpine]", "<", alpOwner, ">"];
ownerCreateAccessList ← NIL;
ownerModifyAccessList ← NIL;
ownerQuota ← 0;
UNTIL ownerProperties = NIL
DO
TRUSTED BEGIN
WITH
ownerProperties.first SELECT FROM
createAccessList => ownerCreateAccessList ← createAccessList;
modifyAccessList => ownerModifyAccessList ← modifyAccessList;
quota => ownerQuota ← quota;
ENDCASE;
END;
ownerProperties ← ownerProperties.rest;
ENDLOOP;
createOwnersFile.PutRope[Rope.Cat["← AlpineCmds.CreateOwner[""", directory, """, ",
Convert.RopeFromInt[from: ownerQuota, base: 10, showRadix: FALSE], "];
"]];

createOwnersFile.PutRope[Rope.Cat["← AlpineCmds.SetOwnerCreateAccess[""", directory, """, ",
GenRopeFromListOfRopes[ownerCreateAccessList], "];
"]];

createOwnersFile.PutRope[Rope.Cat["← AlpineCmds.SetOwnerModifyAccess[""", directory, """, ",
GenRopeFromListOfRopes[ownerModifyAccessList], "];

"]];
BEGIN
EnumProc: PROC [fileName: REF TEXT, universalFile: AE.UniversalFile]
RETURNS [quit: BOOL] =
BEGIN
file: Rope.ROPEIO.PutFR["%g", IO.text[fileName]];
fileProperties: LIST OF AE.PropertyValuePair;
fileModifyAccessList: AE.AccessList ← NIL;
fileReadAccessList: AE.AccessList ← NIL;
segment: BOOLEANFALSE;
dotPlace: INT ← file.Find[".", , TRUE];
IF dotPlace # -1
THEN BEGIN
ENABLE RuntimeError.BoundsFault => GOTO notSegment;
oldDotPlace: INT dotPlace;
UNTIL
(dotPlace ← file.Find[".", oldDotPlace + 1, TRUE]) = -1
DO oldDotPlace ← dotPlace;
ENDLOOP
;
segment Rope.Equal["segment", Rope.Substr[file, oldDotPlace + 1, ], FALSE];
EXITS notSegment => NULL;
END
;
saveAndRestoreFile.PutRope[Rope.Cat[(IF segment THEN "=" ELSE ""), directory, file, "
"]];
fileProperties ← AlpF.Open[transHandle, universalFile, readOnly, [read,
wait]].handle.ReadProperties[];
UNTIL fileProperties = NIL
DO
TRUSTED BEGIN
WITH
fileProperties.first SELECT FROM
modifyAccess => fileModifyAccessList ← modifyAccess;
readAccess => fileReadAccessList ← readAccess;
ENDCASE;
END;
fileProperties ← fileProperties.rest;
ENDLOOP;
setFilePropsFile.PutRope[Rope.Cat["
copy mumble ← [Ivy]<AlpineBackup>luther>", alpOwner, ">", file, "
"
]];
setFilePropsFile.PutRope[Rope.Cat["← AlpineCmds.WheelCopy[from: ""mumble"", to: """,
directory, file, """, enableWheel: TRUE];
"
]];
setFilePropsFile.PutRope["delete mumble
"];
setFilePropsFile.PutRope[Rope.Cat["← AlpineCmds.SetReadAccess[""", directory, file, """, ",
GenRopeFromListOfRopes[fileReadAccessList], "];
"
]];
setFilePropsFile.PutRope[Rope.Cat["← AlpineCmds.SetModifyAccess[""", directory, file, """, ",
GenRopeFromListOfRopes[fileModifyAccessList], "];
"
]];
RETURN[quit: FALSE];
END;
AlpineInterimDirectory.EnumerateDirectoryUnderTrans[transHandle, directory, EnumProc];
END;

ENDLOOP;
[] ← transHandle.Finish[requestedOutcome: commit, continue: FALSE];
createOwnersFile.Close[];
saveAndRestoreFile.Close[];
setFilePropsFile.Close[];
END
;


GenRopeFromListOfRopes: PROCEDURE[accessList: AE.AccessList] RETURNS[rope: Rope.ROPE]
=
BEGIN
first: BOOLEANTRUE;
rope ← "LIST[";
UNTIL
accessList = NIL
DO
IF
first
THEN
first ← FALSE
ELSE rope ← Rope.Cat[rope, ", "];
rope ← Rope.Cat[rope, """", accessList.first, """"];
accessList ← accessList.rest;
ENDLOOP;
rope ← Rope.Cat[rope, "]"];
END;




END.