Skip to content

Commit

Permalink
feat: Allow for setting the excludedPathsList key to an array of path…
Browse files Browse the repository at this point in the history
…s (strings) that can be appended to the urlExclusionsList property.
  • Loading branch information
ryangball committed Oct 30, 2024
1 parent 5936b6b commit 2722d58
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions migrator/AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ struct AppContext {
/// UserDefaults key indicating which policy to use fo handle duplicate files on the destination device.
private static let duplicateFilesHandlingPolicyKey: String = "duplicateFilesHandlingPolicy"

/// UserDefaults key indicating the list of paths to exclude during file discovery
private static let excludedPathsListKey: String = "excludedPathsList"

/// UserDefaults key indicating whether the app should skip the device reboot step after migration.
static let skipRebootUserDefaultsKey: String = "skipDeviceReboot"

Expand Down Expand Up @@ -105,11 +108,16 @@ struct AppContext {
static var duplicateFilesHandlingPolice: DuplicateFilesHandlingPolicy {
return DuplicateFilesHandlingPolicy(rawValue: UserDefaults.standard.string(forKey: Self.duplicateFilesHandlingPolicyKey) ?? "overwrite") ?? .overwrite
}

static var urlExclusionsList: [URL?] {
let managedExcludedPaths = UserDefaults.standard.array(forKey: Self.excludedPathsListKey) as? [String] ?? []
let managedExcludedURLs = managedExcludedPaths.compactMap { URL(string: $0) }
return managedExcludedURLs + defaultUrlExclusionList
}

// MARK: - File Scan Variables
/// Custom list of paths tha needs to be ignored during file discovery.
static var urlExclusionList: [URL?] = [FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first,

/// Custom list of paths that needs to be ignored during file discovery.
static var defaultUrlExclusionList: [URL?] = [FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first,
FileManager.default.urls(for: .applicationDirectory, in: .localDomainMask).first?.appendingPathComponent("\(Bundle.main.name).app"),
FileManager.default.urls(for: .applicationDirectory, in: .localDomainMask).first?.appendingPathComponent("Numbers.app"),
FileManager.default.urls(for: .applicationDirectory, in: .localDomainMask).first?.appendingPathComponent("Pages.app"),
Expand Down

0 comments on commit 2722d58

Please sign in to comment.