<> <> <> <<>> 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]A>B>C>junk.junk"; DeleteAllVersions[name]; space _ TestSpace[0, 0]; <> [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]; <> 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]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: BOOL _ FALSE] = 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]junk.junk", n]; Insert["[Sea-Wolf.alpine]A>junk.junk", n]; Insert["[Sea-Wolf.alpine]B>junk.junk", n]; Insert["[Sea-Wolf.alpine]C>junk.junk", n]; Insert["[Sea-Wolf.alpine]D>junk.junk", n]; Insert["[Sea-Wolf.alpine]E>junk.junk", n]; Insert["[Sea-Wolf.alpine]F>junk.junk", n]; END; Print: PROC [pattern: Rope.ROPE _ NIL, trans: AlpTransaction.Handle _ NIL] = TRUSTED BEGIN newTrans: BOOLEAN _ FALSE; 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]", pattern], name, , trans]}; IF name = NIL OR name.Length[] = 0 THEN EXIT; <> <> <> 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;