@@ -98,21 +98,22 @@ private func migrateFromOldLocations(writeKey: String, to newLocation: URL) {
98
98
// If segment dir already exists in app support, we're done
99
99
guard !fm. fileExists ( atPath: newSegmentDir. path) else { return }
100
100
101
- // Look for old segment directories to move
102
- let oldLocations = [
103
- fm. urls ( for: . documentDirectory, in: . userDomainMask) . first? . appendingPathComponent ( " segment " ) ,
104
- fm. urls ( for: . cachesDirectory, in: . userDomainMask) . first? . appendingPathComponent ( " segment " )
105
- ] . compactMap { $0 }
101
+ // Only check the old location that was actually used on this platform
102
+ #if (os(iOS) || os(watchOS)) && !targetEnvironment(macCatalyst)
103
+ let oldSearchPath = FileManager . SearchPathDirectory. documentDirectory
104
+ #else
105
+ let oldSearchPath = FileManager . SearchPathDirectory. cachesDirectory
106
+ #endif
106
107
107
- for oldSegmentDir in oldLocations {
108
- guard fm . fileExists ( atPath : oldSegmentDir . path ) else { continue }
109
-
110
- do {
111
- try fm . moveItem ( at : oldSegmentDir , to : newSegmentDir )
112
- Analytics . segmentLog ( message : " Migrated analytics data from \( oldSegmentDir . path ) " , kind : . debug )
113
- return // Success!
114
- } catch {
115
- Analytics . segmentLog ( message : " Failed to migrate from \( oldSegmentDir . path ) : \( error ) " , kind : . error )
116
- }
108
+ guard let oldBaseURL = fm . urls ( for: oldSearchPath , in: . userDomainMask ) . first else { return }
109
+ let oldSegmentDir = oldBaseURL . appendingPathComponent ( " segment " )
110
+
111
+ guard fm . fileExists ( atPath : oldSegmentDir . path ) else { return }
112
+
113
+ do {
114
+ try fm . moveItem ( at : oldSegmentDir , to : newSegmentDir )
115
+ Analytics . segmentLog ( message : " Migrated analytics data from \( oldSegmentDir . path ) " , kind : . debug )
116
+ } catch {
117
+ Analytics . segmentLog ( message : " Failed to migrate from \( oldSegmentDir . path ) : \( error ) " , kind : . error )
117
118
}
118
119
}
0 commit comments