diff --git a/Sources/FoundationEssentials/FileManager/SearchPaths/FileManager+WindowsSearchPaths.swift b/Sources/FoundationEssentials/FileManager/SearchPaths/FileManager+WindowsSearchPaths.swift index ba749f6ff..565105ac7 100644 --- a/Sources/FoundationEssentials/FileManager/SearchPaths/FileManager+WindowsSearchPaths.swift +++ b/Sources/FoundationEssentials/FileManager/SearchPaths/FileManager+WindowsSearchPaths.swift @@ -14,12 +14,12 @@ import WinSDK -private func _url(for id: KNOWNFOLDERID) -> URL { +private func _url(for id: KNOWNFOLDERID) -> URL? { var pszPath: PWSTR? let hr: HRESULT = withUnsafePointer(to: id) { id in SHGetKnownFolderPath(id, KF_FLAG_DEFAULT, nil, &pszPath) } - precondition(SUCCEEDED(hr), "SHGetKnownFolderPath failed \(String(hr, radix: 16))") + guard SUCCEEDED(hr) else { return nil } defer { CoTaskMemFree(pszPath) } return URL(filePath: String(decodingCString: pszPath!, as: UTF16.self), directoryHint: .isDirectory) } @@ -27,7 +27,8 @@ private func _url(for id: KNOWNFOLDERID) -> URL { func _WindowsSearchPathURL(for directory: FileManager.SearchPathDirectory, in domain: FileManager.SearchPathDomainMask) -> URL? { switch (directory, domain) { case (.autosavedInformationDirectory, .userDomainMask): - _url(for: FOLDERID_LocalAppData).appending(component: "Autosave Information", directoryHint: .isDirectory) + _url(for: FOLDERID_LocalAppData)? + .appending(component: "Autosave Information", directoryHint: .isDirectory) case (.desktopDirectory, .userDomainMask): _url(for: FOLDERID_Desktop) diff --git a/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift b/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift index 23a7a735d..7ead66838 100644 --- a/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift +++ b/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift @@ -726,7 +726,6 @@ final class FileManagerTests : XCTestCase { .downloadsDirectory, .moviesDirectory, .musicDirectory, - .picturesDirectory, .sharedPublicDirectory ], exists: true) @@ -775,6 +774,12 @@ final class FileManagerTests : XCTestCase { #if !os(watchOS) && !os(tvOS) assertSearchPaths([.trashDirectory], exists: (isMacOS && isFramework) || (!isDarwin && !isWindows)) #endif + + // .picturesDirectory does not exist in CI, though it does exist in user + // desktop scenarios. + #if !os(Windows) + assertSearchPaths([.picturesDirectory], exists: true) + #endif // .applicationScriptsDirectory is only available on macOS and only produces paths in the framework build #if os(macOS)