@@ -113,14 +113,6 @@ public class RepositoryManager {
113
113
precondition ( status == . available, " cloneCheckout() called in invalid state " )
114
114
try self . manager. cloneCheckout ( self , to: path, editable: editable)
115
115
}
116
-
117
- fileprivate func toJSON( ) -> JSON {
118
- return . init( [
119
- " status " : status. rawValue,
120
- " repositoryURL " : repository,
121
- " subpath " : subpath,
122
- ] )
123
- }
124
116
}
125
117
126
118
/// The path under which repositories are stored.
@@ -132,18 +124,6 @@ public class RepositoryManager {
132
124
/// The delegate interface.
133
125
private let delegate : RepositoryManagerDelegate ?
134
126
135
- // FIXME: We should use a more sophisticated map here, which tracks the
136
- // full specifier but then is capable of efficiently determining if two
137
- // repositories map to the same location.
138
- //
139
- /// The map of registered repositories.
140
- fileprivate var repositories : [ String : RepositoryHandle ] = [ : ]
141
-
142
- /// The map of serialized repositories.
143
- ///
144
- /// NOTE: This is to be used only for persistence support.
145
- fileprivate var serializedRepositories : [ String : JSON ] = [ : ]
146
-
147
127
/// Queue to protect concurrent reads and mutations to repositories registery.
148
128
private let serialQueue = DispatchQueue ( label: " org.swift.swiftpm.repomanagerqueue-serial " )
149
129
@@ -159,9 +139,6 @@ public class RepositoryManager {
159
139
/// The filesystem to operate on.
160
140
public let fileSystem : FileSystem
161
141
162
- /// Simple persistence helper.
163
- private let persistence : SimplePersistence
164
-
165
142
/// Create a new empty manager.
166
143
///
167
144
/// - Parameters:
@@ -185,24 +162,6 @@ public class RepositoryManager {
185
162
self . operationQueue = OperationQueue ( )
186
163
self . operationQueue. name = " org.swift.swiftpm.repomanagerqueue-concurrent "
187
164
self . operationQueue. maxConcurrentOperationCount = 10
188
-
189
- self . persistence = SimplePersistence (
190
- fileSystem: fileSystem,
191
- schemaVersion: 1 ,
192
- statePath: path. appending ( component: " checkouts-state.json " ) )
193
-
194
- // Load the state from disk, if possible.
195
- do {
196
- _ = try self . persistence. restoreState ( self )
197
- } catch {
198
- // State restoration errors are ignored, for now.
199
- //
200
- // FIXME: We need to do something better here.
201
- print ( " warning: unable to restore checkouts state: \( error) " )
202
-
203
- // Try to save the empty state.
204
- try ? self . persistence. saveState ( self )
205
- }
206
165
}
207
166
208
167
/// Get a handle to a repository.
@@ -282,21 +241,6 @@ public class RepositoryManager {
282
241
self . callbacksQueue. async {
283
242
self . delegate? . fetchingDidFinish ( handle: handle, error: fetchError)
284
243
}
285
-
286
- // Save the manager state.
287
- self . serialQueue. sync {
288
- do {
289
- // Update the serialized repositories map.
290
- //
291
- // We do this so we don't have to read the other
292
- // handles when saving the sate of this handle.
293
- self . serializedRepositories [ repository. url] = handle. toJSON ( )
294
- try self . persistence. saveState ( self )
295
- } catch {
296
- // FIXME: Handle failure gracefully, somehow.
297
- fatalError ( " unable to save manager state \( error) " )
298
- }
299
- }
300
244
}
301
245
// Call the completion handler.
302
246
self . callbacksQueue. async {
@@ -311,20 +255,11 @@ public class RepositoryManager {
311
255
/// Note: This method is thread safe.
312
256
private func getHandle( repository: RepositorySpecifier ) -> RepositoryHandle {
313
257
return serialQueue. sync {
314
-
315
- // Reset if the state file was deleted during the lifetime of RepositoryManager.
316
- if !self . serializedRepositories. isEmpty && !self . persistence. stateFileExists ( ) {
317
- self . unsafeReset ( )
318
- }
319
-
320
- let handle : RepositoryHandle
321
- if let oldHandle = self . repositories [ repository. url] {
322
- handle = oldHandle
323
- } else {
324
- let subpath = RelativePath ( repository. fileSystemIdentifier)
325
- let newHandle = RepositoryHandle ( manager: self , repository: repository, subpath: subpath)
326
- self . repositories [ repository. url] = newHandle
327
- handle = newHandle
258
+ let subpath = RelativePath ( repository. fileSystemIdentifier)
259
+ let handle = RepositoryHandle ( manager: self , repository: repository, subpath: subpath)
260
+ let repositoryPath = path. appending ( RelativePath ( repository. fileSystemIdentifier) )
261
+ if fileSystem. exists ( repositoryPath) {
262
+ handle. status = . available
328
263
}
329
264
return handle
330
265
}
@@ -352,15 +287,8 @@ public class RepositoryManager {
352
287
/// Removes the repository.
353
288
public func remove( repository: RepositorySpecifier ) throws {
354
289
try serialQueue. sync {
355
- // If repository isn't present, we're done.
356
- guard let handle = repositories [ repository. url] else {
357
- return
358
- }
359
- repositories [ repository. url] = nil
360
- serializedRepositories [ repository. url] = nil
361
- let repositoryPath = path. appending ( handle. subpath)
290
+ let repositoryPath = path. appending ( RelativePath ( repository. fileSystemIdentifier) )
362
291
try fileSystem. removeFileTree ( repositoryPath)
363
- try self . persistence. saveState ( self )
364
292
}
365
293
}
366
294
@@ -375,31 +303,10 @@ public class RepositoryManager {
375
303
376
304
/// Performs the reset operation without the serial queue.
377
305
private func unsafeReset( ) {
378
- self . repositories = [ : ]
379
- self . serializedRepositories = [ : ]
380
306
try ? self . fileSystem. removeFileTree ( path)
381
307
}
382
308
}
383
309
384
- // MARK: Persistence
385
- extension RepositoryManager : SimplePersistanceProtocol {
386
-
387
- public func restore( from json: JSON ) throws {
388
- // Update the serialized repositories.
389
- //
390
- // We will use this to save the state so we don't have to read the other
391
- // handles when saving the sate of a handle.
392
- self . serializedRepositories = try json. get ( " repositories " )
393
- self . repositories = try serializedRepositories. mapValues ( {
394
- try RepositoryHandle ( manager: self , json: $0)
395
- } )
396
- }
397
-
398
- public func toJSON( ) -> JSON {
399
- return JSON ( [ " repositories " : JSON ( self . serializedRepositories) ] )
400
- }
401
- }
402
-
403
310
extension RepositoryManager . RepositoryHandle : CustomStringConvertible {
404
311
public var description : String {
405
312
return " < \( type ( of: self ) ) subpath: \( subpath) > "
0 commit comments