From a2c7d0c5b067af7d7ec5a06f4556f7801684e5d8 Mon Sep 17 00:00:00 2001 From: Tristan Celder Date: Fri, 21 Jun 2024 10:57:24 +0100 Subject: [PATCH] update storage directory for PersistentStorage --- .../Storages/PersistentStorage.swift | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Sources/Amplitude/Storages/PersistentStorage.swift b/Sources/Amplitude/Storages/PersistentStorage.swift index 4f7cef4..2018549 100644 --- a/Sources/Amplitude/Storages/PersistentStorage.swift +++ b/Sources/Amplitude/Storages/PersistentStorage.swift @@ -281,23 +281,18 @@ extension PersistentStorage { } internal func getEventsStorageDirectory(createDirectory: Bool = true) -> URL { - // TODO: Update to use applicationSupportDirectory for all platforms (this will require a migration) - // let searchPathDirectory = FileManager.SearchPathDirectory.applicationSupportDirectory - // 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/\(appPath ?? "")\(eventsFileKey)/") + var storageUrl = docUrl.appendingPathComponent("amplitude/\(appPath ?? "")\(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 }