@@ -57,9 +57,7 @@ extension DiskPersistence {
5757extension DiskPersistence . Datastore {
5858 /// The URL that points to the Datastore directory.
5959 nonisolated var datastoreURL : URL {
60- snapshot
61- . datastoresURL
62- . appendingPathComponent ( " \( id) .datastore " , isDirectory: true )
60+ snapshot. datastoreURL ( for: id)
6361 }
6462
6563 /// The URL that points to the Root directory.
@@ -68,40 +66,62 @@ extension DiskPersistence.Datastore {
6866 . appendingPathComponent ( " Root " , isDirectory: true )
6967 }
7068
69+ /// The URL for the specified root.
70+ nonisolated func rootURL( for id: DatastoreRootIdentifier ) -> URL {
71+ rootURL. appendingPathComponent ( " \( id) .json " , isDirectory: false )
72+ }
73+
7174 /// The URL that points to the DirectIndexes directory.
7275 nonisolated var directIndexesURL : URL {
73- datastoreURL
74- . appendingPathComponent ( " DirectIndexes " , isDirectory: true )
76+ datastoreURL. appendingPathComponent ( " DirectIndexes " , isDirectory: true )
7577 }
7678
7779 /// The URL that points to the SecondaryIndexes directory.
7880 nonisolated var secondaryIndexesURL : URL {
79- datastoreURL
80- . appendingPathComponent ( " SecondaryIndexes " , isDirectory: true )
81+ datastoreURL. appendingPathComponent ( " SecondaryIndexes " , isDirectory: true )
8182 }
8283
83- nonisolated func indexURL( for indexID: Index . ID ) -> URL {
84+ /// The root URL of a partifular index directory.
85+ nonisolated func indexURL( for indexID: DatastoreRootManifest . IndexID ) -> URL {
8486 switch indexID {
8587 case . primary:
86- return directIndexesURL
87- . appendingPathComponent ( " Primary.datastoreindex " , isDirectory: true )
88- case . direct( let indexID, _) :
89- return directIndexesURL
90- . appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
91- case . secondary( let indexID, _) :
92- return secondaryIndexesURL
93- . appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
88+ directIndexesURL. appendingPathComponent ( " Primary.datastoreindex " , isDirectory: true )
89+ case . direct( let indexID) :
90+ directIndexesURL. appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
91+ case . secondary( let indexID) :
92+ secondaryIndexesURL. appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
9493 }
9594 }
9695
97- nonisolated func manifestsURL( for indexID: Index . ID ) -> URL {
98- indexURL ( for: indexID)
99- . appendingPathComponent ( " Manifest " , isDirectory: true )
96+ /// The URL of an index's manifests directory.
97+ nonisolated func manifestsURL( for id: DatastoreRootManifest . IndexID ) -> URL {
98+ indexURL ( for: id) . appendingPathComponent ( " Manifest " , isDirectory: true )
99+ }
100+
101+ /// The URL of an index's root manifest.
102+ nonisolated func manifestURL( for id: Index . ID ) -> URL {
103+ manifestURL ( for: DatastoreRootManifest . IndexManifestID ( id) )
100104 }
101105
102- nonisolated func pagesURL( for indexID: Index . ID ) -> URL {
103- indexURL ( for: indexID)
104- . appendingPathComponent ( " Pages " , isDirectory: true )
106+ /// The URL of an index's root manifest.
107+ nonisolated func manifestURL( for id: DatastoreRootManifest . IndexManifestID ) -> URL {
108+ manifestsURL ( for: id. indexID) . appendingPathComponent ( " \( id. manifestID) .indexmanifest " , isDirectory: false )
109+ }
110+
111+ /// The URL of an index's pages directory..
112+ nonisolated func pagesURL( for id: Index . ID ) -> URL {
113+ indexURL ( for: id. indexID) . appendingPathComponent ( " Pages " , isDirectory: true )
114+ }
115+
116+ /// The URL of a particular page.
117+ nonisolated func pageURL( for id: Page . ID ) -> URL {
118+ guard let components = try ? id. page. components else { preconditionFailure ( " Components could not be determined for Page. " ) }
119+
120+ return pagesURL ( for: id. index)
121+ . appendingPathComponent ( components. year, isDirectory: true )
122+ . appendingPathComponent ( components. monthDay, isDirectory: true )
123+ . appendingPathComponent ( components. hourMinute, isDirectory: true )
124+ . appendingPathComponent ( " \( id. page) .datastorepage " , isDirectory: false )
105125 }
106126}
107127
@@ -198,7 +218,7 @@ extension DiskPersistence.Datastore {
198218extension DiskPersistence . Datastore {
199219 /// Load the root object from disk for the given identifier.
200220 func loadRootObject( for rootIdentifier: DatastoreRootIdentifier ) throws -> DatastoreRootManifest {
201- let rootObjectURL = rootURL. appendingPathComponent ( " \( rootIdentifier ) .json " , isDirectory : false )
221+ let rootObjectURL = rootURL ( for : rootIdentifier )
202222
203223 let data = try Data ( contentsOf: rootObjectURL)
204224
@@ -218,7 +238,7 @@ extension DiskPersistence.Datastore {
218238 try FileManager . default. createDirectory ( at: secondaryIndexesURL, withIntermediateDirectories: true )
219239 }
220240
221- let rootObjectURL = rootURL. appendingPathComponent ( " \( manifest. id) .json " , isDirectory : false )
241+ let rootObjectURL = rootURL ( for : manifest. id)
222242
223243 /// Encode the provided manifest, and write it to disk.
224244 let data = try JSONEncoder . shared. encode ( manifest)
0 commit comments