AlpDirectoryTestImpl.mesa
Last edited by: John Maxwell on: November 23, 1983 10:39 am
Last Edited by: Hauser, December 12, 1984 5:23:36 pm PST
DIRECTORY
AlpDirectory,
AlpFile USING [Close, GetSize, GetUniversalFile, Handle, ReadProperties],
AlpineEnvironment,
AlpInstance USING [Create, Handle],
AlpTransaction USING [Create, Finish, GetNextVolumeGroup, Handle, ReadOwnerProperties],
IO USING [card, int, Put, PutRope, refAny, rope, STREAM, time],
Rope USING [Cat, Equal, Find, Length, ROPE, Substr],
ViewerIO USING [CreateViewerStreams];
AlpDirectoryTestImpl: CEDAR PROGRAM
IMPORTS AlpDirectory, AlpFile, AlpInstance, AlpTransaction, IO, Rope, ViewerIO = BEGIN
OPEN AlpineEnvironment;
server: Rope.ROPE ← "Sea-Wolf.alpine";
Problem: SIGNAL = CODE;
Test: PROC = TRUSTED BEGIN
OPEN AlpDirectory;
space: PageCount;
file: UniversalFile;
outcome: Outcome;
openFileID: AlpFile.Handle;
fullPathName, link: Rope.ROPE;
props: LIST OF PropertyValuePair;
name: Rope.ROPE ← "[Sea-Wolf.alpine]<Hauser.pa>A>B>C>junk.junk";
DeleteAllVersions[name];
space ← TestSpace[0, 0];
Test naming and creation.
[openFileID, fullPathName] ← CreateFile["/Sea-Wolf.alpine/Hauser.pa/A/B/C/junk.junk", 1];
IF ~Rope.Equal[Rope.Substr[fullPathName, 0, Rope.Find[fullPathName, "!"]], name] THEN Problem;
props ← AlpFile.ReadProperties[openFileID];
FOR props ← props, props.rest WHILE props # NIL DO
WITH p: props.first SELECT FROM
byteLength => IF p.byteLength # 0 THEN Problem;
owner => IF ~Rope.Equal[p.owner, "Hauser.pa", FALSE] THEN Problem;
stringName => IF ~Rope.Equal[p.stringName, "A>B>C>junk.junk!1"] THEN Problem;
ENDCASE;
ENDLOOP;
[file, fullPathName, link] ← Lookup[name, openFileID.trans];
IF link # NIL THEN Problem;
IF AlpFile.GetUniversalFile[openFileID] # file THEN Problem;
IF AlpFile.GetSize[openFileID] # 1 THEN Problem;
AlpFile.Close[openFileID];
outcome ← AlpTransaction.Finish[openFileID.trans, commit];
IF outcome = commit THEN [] ← TestSpace[space, 2];
Test the keep properties.
DeleteAllVersions[name];
space ← TestSpace[0, 0];
SetDefaultKeep["Sea-Wolf.alpine", "Hauser.pa", 3];
THROUGH [1..4] DO
[openFileID,] ← CreateFile[name, 1];
AlpFile.Close[openFileID];
outcome ← AlpTransaction.Finish[openFileID.trans, commit];
ENDLOOP;
IF Lookup[Rope.Cat[name, "!1"]].fullPathName # NIL THEN Problem;
IF Lookup[Rope.Cat[name, "!2"]].fullPathName = NIL THEN Problem;
[] ← DisableKeep[Rope.Cat[name, "!2"]];
THROUGH [5..6] DO
[openFileID,] ← CreateFile[name, 1];
AlpFile.Close[openFileID];
outcome ← AlpTransaction.Finish[openFileID.trans, commit];
ENDLOOP;
IF Lookup[Rope.Cat[name, "!2"]].fullPathName = NIL THEN Problem;
IF Lookup[Rope.Cat[name, "!3"]].fullPathName # NIL THEN Problem;
[] ← SetKeep[name, 2];
IF Lookup[Rope.Cat[name, "!2"]].fullPathName = NIL THEN Problem;
IF Lookup[Rope.Cat[name, "!4"]].fullPathName # NIL THEN Problem;
THROUGH [7..7] DO
[openFileID,] ← CreateFile[name, 1];
AlpFile.Close[openFileID];
outcome ← AlpTransaction.Finish[openFileID.trans, commit];
ENDLOOP;
IF Lookup[Rope.Cat[name, "!5"]].fullPathName # NIL THEN Problem;
IF Lookup[Rope.Cat[name, "!6"]].fullPathName = NIL THEN Problem;
[] ← SetKeep[name, 4];
THROUGH [8..10] DO
[openFileID,] ← CreateFile[name, 1];
AlpFile.Close[openFileID];
outcome ← AlpTransaction.Finish[openFileID.trans, commit];
ENDLOOP;
IF Lookup[Rope.Cat[name, "!6"]].fullPathName # NIL THEN Problem;
IF Lookup[Rope.Cat[name, "!7"]].fullPathName = NIL THEN Problem;
space ← TestSpace[space, 10];
END;
Test2: PROC = TRUSTED BEGIN
OPEN AlpDirectory;
outcome: Outcome;
name: Rope.ROPE ← "[Sea-Wolf.alpine]<Hauser.pa>A>B>C>junk.junk";
trans: AlpTransaction.Handle ← AlpTransaction.Create[AlpInstance.Create[server]];
DeleteAllVersions[name];
[] ← Insert[name, AlpineEnvironment.nullUniversalFile, , trans];
Print["*", trans];
outcome ← trans.Finish[commit];
Print["*"];
END;
TestSpace: PROC[space: PageCount, delta: INT, owner: Rope.ROPE ← "Hauser.pa"]
RETURNS[new: PageCount] = BEGIN
trans: AlpTransaction.Handle;
ownerPropertySet: OwnerPropertySet;
ownerProps: LIST OF OwnerPropertyValuePair;
ownerPropertySet ← ALL[FALSE];
ownerPropertySet[spaceInUse] ← TRUE;
trans ← AlpTransaction.Create[instHandle: AlpInstance.Create[server], createLocalWorker: TRUE];
ownerProps ← AlpTransaction.ReadOwnerProperties[trans, AlpTransaction.GetNextVolumeGroup[trans], "Hauser.pa", ownerPropertySet];
TRUSTED {WITH p: ownerProps.first SELECT FROM spaceInUse => new ← p.spaceInUse; ENDCASE};
IF space = 0 THEN RETURN;
IF space + delta # new THEN Problem;
END;
DeleteAllVersions: PROC[pattern: Rope.ROPE] = TRUSTED BEGIN
fileName: Rope.ROPE;
WHILE TRUE DO
fileName ← AlpDirectory.Enumerate[pattern, fileName].fullPathName;
IF fileName = NIL THEN EXIT;
[] ← AlpDirectory.DeleteFile[fileName];
ENDLOOP;
END;
Fill: PROC[n: CARDINAL ← 10, transaction: BOOLFALSE] = BEGIN
trans: AlpTransaction.Handle;
Insert: PROC[fileName: Rope.ROPE, n: CARDINAL] = TRUSTED INLINE BEGIN
FOR i: CARDINAL IN [0..n) DO
[] ← AlpDirectory.Insert[fileName, nullUniversalFile, 0, trans];
ENDLOOP;
END;
IF transaction THEN trans ← AlpTransaction.Create[AlpInstance.Create[server]];
Insert["[Sea-Wolf.alpine]<Hauser.pa>junk.junk", n];
Insert["[Sea-Wolf.alpine]<Hauser.pa>A>junk.junk", n];
Insert["[Sea-Wolf.alpine]<Hauser.pa>B>junk.junk", n];
Insert["[Sea-Wolf.alpine]<Hauser.pa>C>junk.junk", n];
Insert["[Sea-Wolf.alpine]<Hauser.pa>D>junk.junk", n];
Insert["[Sea-Wolf.alpine]<Hauser.pa>E>junk.junk", n];
Insert["[Sea-Wolf.alpine]<Hauser.pa>F>junk.junk", n];
END;
Print: PROC [pattern: Rope.ROPENIL, trans: AlpTransaction.Handle ← NIL] = TRUSTED BEGIN
newTrans: BOOLEANFALSE;
BEGIN
ENABLE UNWIND => IF newTrans AND trans # NIL THEN [] ← trans.Finish[abort];
stream: IO.STREAM;
file: UniversalFile;
name, link: Rope.ROPE;
inst: AlpInstance.Handle;
ownerProps: LIST OF OwnerPropertyValuePair;
inst ← AlpInstance.Create[server];
IF trans = NIL THEN {
newTrans ← TRUE;
trans ← AlpTransaction.Create[instHandle: inst, createLocalWorker: TRUE]};
stream ← ViewerIO.CreateViewerStreams["directory.log"].out;
stream.PutRope["\n"];
ownerProps ← AlpTransaction.ReadOwnerProperties[trans, AlpTransaction.GetNextVolumeGroup[trans], "Hauser.pa"];
FOR ownerProps ← ownerProps, ownerProps.rest WHILE ownerProps # NIL DO
TRUSTED {WITH p: ownerProps.first SELECT FROM
createAccessList => stream.Put[IO.rope[" createAccess: "], IO.refAny[p.createAccessList]];
modifyAccessList => stream.Put[IO.rope[" modifyAccess: "], IO.refAny[p.modifyAccessList]];
quota => stream.Put[IO.rope[" quota: "], IO.int[p.quota]];
spaceInUse =>stream.Put[IO.rope[" spaceInUse: "], IO.int[p.spaceInUse]];
ENDCASE};
ENDLOOP;
stream.PutRope["\n\n"];
IF pattern = NIL THEN pattern ← "*";
WHILE TRUE DO
TRUSTED {[file, name, link] ← AlpDirectory.Enumerate[Rope.Cat["[Sea-Wolf.alpine]<Hauser.pa>", pattern], name, , trans]};
IF name = NIL OR name.Length[] = 0 THEN EXIT;
PrintID[stream, LOOPHOLE[file.volumeID]];
PrintID[stream, LOOPHOLE[file.fileID]];
stream.PutRope[": "];
stream.PutRope[name];
IF link # NIL THEN stream.Put[IO.rope[" => "], IO.rope[link]];
stream.PutRope["\n"];
IF file # nullUniversalFile THEN {
openFileID: AlpFile.Handle;
props: LIST OF PropertyValuePair;
openFileID ← AlpDirectory.OpenFile[name: name, transHandle: trans].openFileID;
props ← AlpFile.ReadProperties[openFileID];
FOR props ← props, props.rest WHILE props # NIL DO
WITH p: props.first SELECT FROM
byteLength => stream.Put[IO.rope[" byteLength: "], IO.int[p.byteLength]];
createTime => stream.Put[IO.rope[" createTime: "], IO.time[p.createTime]];
highWaterMark => stream.Put[IO.rope[" highWaterMark: "], IO.int[p.highWaterMark]];
modifyAccess => stream.Put[IO.rope[" modifyAccess: "], IO.refAny[p.modifyAccess]];
owner => stream.Put[IO.rope[" owner: "], IO.rope[p.owner]];
readAccess => stream.Put[IO.rope[" readAccess: "], IO.refAny[p.readAccess]];
stringName => stream.Put[IO.rope[" stringName: "], IO.rope[p.stringName]];
version => stream.Put[IO.rope[" version: "], IO.int[p.version]];
ENDCASE;
ENDLOOP;
stream.PutRope["\n"];
AlpFile.Close[openFileID]};
ENDLOOP;
IF newTrans THEN [] ← trans.Finish[requestedOutcome: commit, continue: FALSE];
END;
END;
END.
PrintID: PROC
[stream: IO.STREAM, id: System.UniversalID] = BEGIN
idRep: RECORD[a, b, c, d, e: CARDINAL] ← LOOPHOLE[id];
IF stream = NIL THEN RETURN;
stream.Put[IO.card[idRep.a], IO.char[IO.SP]];
stream.Put[IO.card[idRep.b], IO.char[IO.SP]];
stream.Put[IO.card[idRep.c], IO.char[IO.SP]];
stream.Put[IO.card[idRep.d], IO.char[IO.SP]];
stream.Put[IO.card[idRep.e], IO.char[IO.SP]];
END;