Skip to content

Commit db45d9f

Browse files
author
Ken Carroll
committed
Use FileManager instead of attributes.
1 parent 5b04418 commit db45d9f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

Source/Shared/Storage/DiskStorage.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ final public class DiskStorage<Key: Hashable, Value> {
1717

1818
private let transformer: Transformer<Value>
1919
private let hasher = Hasher.constantAccrossExecutions()
20-
private var defaultFileAttributes: [FileAttributeKey : Any]?
20+
// private var defaultFileAttributes: [FileAttributeKey : Any]?
2121

2222
// MARK: - Initialization
23-
public convenience init(config: DiskConfig, fileManager: FileManager = FileManager.default, transformer: Transformer<Value>,
24-
fileAttributes: [FileAttributeKey : Any] = [:]) throws {
23+
public convenience init(config: DiskConfig, fileManager: FileManager = FileManager.default, transformer: Transformer<Value>) throws {
2524
let url: URL
2625
if let directory = config.directory {
2726
url = directory
@@ -47,7 +46,7 @@ final public class DiskStorage<Key: Hashable, Value> {
4746
])
4847
}
4948

50-
defaultFileAttributes = fileAttributes
49+
// defaultFileAttributes = fileAttributes
5150

5251
}
5352

@@ -85,11 +84,11 @@ extension DiskStorage: StorageAware {
8584
let expiry = expiry ?? config.expiry
8685
let data = try transformer.toData(object)
8786
let filePath = makeFilePath(for: key)
88-
var attributes = defaultFileAttributes!
89-
attributes[.modificationDate] = expiry.date
90-
91-
_ = fileManager.createFile(atPath: filePath, contents: data, attributes: attributes)
92-
// try fileManager.setAttributes([.modificationDate: expiry.date], ofItemAtPath: filePath)
87+
// var attributes = defaultFileAttributes!
88+
// attributes[.modificationDate] = expiry.date
89+
//
90+
_ = fileManager.createFile(atPath: filePath, contents: data, attributes: nil)
91+
try fileManager.setAttributes([.modificationDate: expiry.date], ofItemAtPath: filePath)
9392
}
9493

9594
public func removeObject(forKey key: Key) throws {

Source/Shared/Storage/Storage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public final class Storage<Key: Hashable, Value> {
1515
/// - diskConfig: Configuration for disk storage
1616
/// - memoryConfig: Optional. Pass config if you want memory cache
1717
/// - Throws: Throw StorageError if any.
18-
public convenience init(diskConfig: DiskConfig, memoryConfig: MemoryConfig, transformer: Transformer<Value>) throws {
19-
let disk = try DiskStorage<Key, Value>(config: diskConfig, transformer: transformer)
18+
public convenience init(diskConfig: DiskConfig, memoryConfig: MemoryConfig, fileManager: FileManager, transformer: Transformer<Value>) throws {
19+
let disk = try DiskStorage<Key, Value>(config: diskConfig, fileManager: fileManager, transformer: transformer)
2020
let memory = MemoryStorage<Key, Value>(config: memoryConfig)
2121
let hybridStorage = HybridStorage(memoryStorage: memory, diskStorage: disk)
2222
self.init(hybridStorage: hybridStorage)

0 commit comments

Comments
 (0)