@@ -55,56 +55,11 @@ extension DiskPersistence.Datastore.Index {
5555// MARK: - Common URL Accessors
5656
5757extension DiskPersistence . Datastore . Index {
58- /// The URL that points to the index.
59- nonisolated var indexURL : URL {
60- switch id {
61- case . primary:
62- return datastore
63- . directIndexesURL
64- . appendingPathComponent ( " Primary.datastoreindex " , isDirectory: true )
65- case . direct( let indexID, _) :
66- return datastore
67- . directIndexesURL
68- . appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
69- case . secondary( let indexID, _) :
70- return datastore
71- . secondaryIndexesURL
72- . appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
73- }
74- }
75-
76- /// The URL that points to the Manifest directory.
77- nonisolated var manifestsURL : URL {
78- indexURL. appendingPathComponent ( " Manifest " , isDirectory: true )
79- }
80-
81- /// The URL that points to the Manifest directory.
82- nonisolated var pagesURL : URL {
83- indexURL. appendingPathComponent ( " Pages " , isDirectory: true )
84- }
85-
8658 /// The URL that points to the manifest.
8759 nonisolated var manifestURL : URL {
88- switch id {
89- case . primary( let manifestID) :
90- return datastore
91- . directIndexesURL
92- . appendingPathComponent ( " Primary.datastoreindex " , isDirectory: true )
93- . appendingPathComponent ( " Manifest " , isDirectory: true )
94- . appendingPathComponent ( " \( manifestID) .indexmanifest " , isDirectory: false )
95- case . direct( let indexID, let manifestID) :
96- return datastore
97- . directIndexesURL
98- . appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
99- . appendingPathComponent ( " Manifest " , isDirectory: true )
100- . appendingPathComponent ( " \( manifestID) .indexmanifest " , isDirectory: false )
101- case . secondary( let indexID, let manifestID) :
102- return datastore
103- . secondaryIndexesURL
104- . appendingPathComponent ( " \( indexID) .datastoreindex " , isDirectory: true )
105- . appendingPathComponent ( " Manifest " , isDirectory: true )
106- . appendingPathComponent ( " \( manifestID) .indexmanifest " , isDirectory: false )
107- }
60+ datastore
61+ . manifestsURL ( for: id)
62+ . appendingPathComponent ( " \( id. manifestID) .indexmanifest " , isDirectory: false )
10863 }
10964}
11065
@@ -134,10 +89,26 @@ extension DiskPersistence.Datastore.Index {
13489 }
13590
13691 /// Make sure the directories exists first.
137- try FileManager . default. createDirectory ( at: manifestsURL, withIntermediateDirectories: true )
92+ try FileManager . default. createDirectory ( at: datastore . manifestsURL ( for : id ) , withIntermediateDirectories: true )
13893
13994 /// Encode the provided manifest, and write it to disk.
14095 let data = Data ( manifest. bytes)
14196 try data. write ( to: manifestURL, options: . atomic)
14297 }
14398}
99+
100+ // MARK: - Pages
101+
102+ extension DiskPersistence . Datastore . Index {
103+ var orderedPages : [ DiskPersistence . Datastore . Page ] {
104+ get async throws {
105+ var pages : [ DiskPersistence . Datastore . Page ] = [ ]
106+
107+ for pageID in try await manifest. orderedPageIDs {
108+ pages. append ( await datastore. page ( for: . init( index: id, page: pageID) ) )
109+ }
110+
111+ return pages
112+ }
113+ }
114+ }
0 commit comments