Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow for setting the excludedPathsList key to an array of paths (strings) that can be appended to the urlExclusionsList property. #12

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 urlExclusionList: [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
Loading