Skip to content

Foundation: adjust NSTemporaryDirectory for Windows #1940

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

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

compnerd
Copy link
Member

Windows provides GetTempPath for getting the temporary directory which
consults the environment variables and falls back through a cascading
set ultimately ending up at %SystemRoot%\Temp if nothing else is
found. The last path is not exactly great, but, we do not expect to end
up there as modern Windows will use %UserProfile%\Local Settings
before that.

@compnerd
Copy link
Member Author

@compnerd
Copy link
Member Author

@swift-ci please test

gwynne
gwynne previously requested changes Feb 23, 2019
@gwynne
Copy link
Contributor

gwynne commented Feb 23, 2019

The returned value should really be cached on all platforms, I think... I don’t know what the expected behavior of the function is if the env vars change between calls. @millenomi ?

@gwynne gwynne dismissed their stale review February 23, 2019 04:54

Changes will be made separately.

Copy link
Contributor

@gwynne gwynne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but would definitely like to see the fix for the macOS version of the code as well

@compnerd
Copy link
Member Author

@swift-ci please test macOS platform

@compnerd
Copy link
Member Author

Ugh, this is wrong. This changed the semantics for the macOS target, as it would previously fall back to the TMP env var in the truncation case.

@compnerd
Copy link
Member Author

@swift-ci please test

_ = GetTempPathW(cchLength + 1, wszPath.baseAddress)
return String(decodingCString: wszPath.baseAddress!, as: UTF16.self)
#else
#if os(macOS) || os(iOS)
Copy link
Contributor

@millenomi millenomi Feb 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is absolutely where canImport(Darwin) should go, since the point of this block is to guard from using API that exists in that module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still hate canImport(Darwin), but fine. Although, I think that it should be done in #1941 rather than in this change. I'll update that in a little while.

Windows provides `GetTempPath` for getting the temporary directory which
consults the environment variables and falls back through a cascading
set ultimately ending up at `%SystemRoot%\Temp` if nothing else is
found.  The last path is not exactly great, but, we do not expect to end
up there as modern Windows will use `%UserProfile%\Local Settings`
before that.
@compnerd
Copy link
Member Author

@swift-ci please test

1 similar comment
@compnerd
Copy link
Member Author

@swift-ci please test

@millenomi millenomi merged commit 856eb09 into swiftlang:master Feb 25, 2019
@compnerd compnerd deleted the temporary branch February 15, 2020 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants