Skip to content

Commit

Permalink
update storage directory for PersistentStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
tcldr committed Dec 16, 2023
1 parent 353b334 commit 6c6a768
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Sources/Amplitude/Storages/PersistentStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,18 @@ extension PersistentStorage {
}

internal func getEventsStorageDirectory(createDirectory: Bool = true) -> URL {
// tvOS doesn't have access to document
// macOS /Documents dir might be synced with iCloud
#if os(tvOS) || os(macOS)
let searchPathDirectory = FileManager.SearchPathDirectory.cachesDirectory
#else
let searchPathDirectory = FileManager.SearchPathDirectory.documentDirectory
#endif

let searchPathDirectory = FileManager.SearchPathDirectory.applicationSupportDirectory
let urls = fileManager.urls(for: searchPathDirectory, in: .userDomainMask)
let docUrl = urls[0]
let storageUrl = docUrl.appendingPathComponent("amplitude/\(eventsFileKey)/")
var storageUrl = docUrl.appendingPathComponent("amplitude/\(eventsFileKey)/")
if createDirectory {
// try to create it, will fail if already exists.
// tvOS, watchOS regularly clear out data.
try? FileManager.default.createDirectory(at: storageUrl, withIntermediateDirectories: true, attributes: nil)
var values = URLResourceValues()
values.isExcludedFromBackup = true
try? FileManager.default.createDirectory(
at: storageUrl, withIntermediateDirectories: true, attributes: nil)
try? storageUrl.setResourceValues(values)
}
return storageUrl
}
Expand Down

0 comments on commit 6c6a768

Please sign in to comment.