Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

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)
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ final class FileManagerTests : XCTestCase {
.downloadsDirectory,
.moviesDirectory,
.musicDirectory,
.picturesDirectory,
.sharedPublicDirectory
], exists: true)

Expand Down Expand Up @@ -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)
Expand Down