Skip to content

Commit

Permalink
Merge pull request #12 from alectrona/allow-managed-exclusions
Browse files Browse the repository at this point in the history
feat: Allow for setting the excludedPathsList key to an array of paths (strings) that can be appended to the urlExclusionsList property.
  • Loading branch information
SMartorelli authored Oct 31, 2024
2 parents 5936b6b + 2e308f9 commit 078cbd1
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 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

0 comments on commit 078cbd1

Please sign in to comment.