diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66234259..6015d037 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: xcode: - - 15.2 + - 15.4 platform: - iOS env: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8c9887e8..9cc92e21 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: xcode: - - 15.2 + - 15.4 platform: - iOS language: [ 'swift' ] diff --git a/MoppApp/MoppApp/Extensions/URL+Additions.swift b/MoppApp/MoppApp/Extensions/URL+Additions.swift index 4a2604de..bbf80115 100644 --- a/MoppApp/MoppApp/Extensions/URL+Additions.swift +++ b/MoppApp/MoppApp/Extensions/URL+Additions.swift @@ -30,20 +30,36 @@ extension URL { } func getValidPath() -> URL? { - guard let appDirectoryURL = FileManager.default.urls(for: .applicationDirectory, in: .userDomainMask).first else { - return nil - } - - guard let subdirectoryURLs = try? FileManager.default.contentsOfDirectory(at: appDirectoryURL, includingPropertiesForKeys: nil, options: .skipsHiddenFiles) else { - return nil + let directories: [FileManager.SearchPathDirectory] = [ + .documentDirectory, + .downloadsDirectory, + .userDirectory, + .libraryDirectory, + ] + + let currentURL = URL(fileURLWithPath: self.path).resolvingSymlinksInPath() + let currentURLPath = currentURL.path + + for directory in directories { + guard let directoryURL = FileManager.default.urls(for: directory, in: .userDomainMask).first else { + continue + } + + guard let subdirectoryURLs = try? FileManager.default.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys: nil, options: .skipsHiddenFiles) else { + continue } for subdirectoryURL in subdirectoryURLs { - let subdirectoryFilePath = FilePath(stringLiteral: subdirectoryURL.path) - if (FilePath(stringLiteral: self.path).starts(with: subdirectoryFilePath.lexicallyNormalized())) { - return URL(fileURLWithPath: subdirectoryFilePath.description) + let resolvedSubdirectoryURL = subdirectoryURL.resolvingSymlinksInPath() + let resolvedSubdirectoryPath = resolvedSubdirectoryURL.path + + if FilePath(stringLiteral: currentURLPath).starts(with: FilePath(stringLiteral: resolvedSubdirectoryPath)) { + return currentURL } } - return nil + } + + return nil } + }