-
Notifications
You must be signed in to change notification settings - Fork 654
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
NIOFileSystem
: Try ${TMPDIR} first for temporary directory
#3067
base: main
Are you sure you want to change the base?
Conversation
Motivation: This PR aligns what temp directory NIOFileSystem will return first: - First try `${TMPDIR}` as it's an expressed user preference - On Darwin, try `_CS_DARWIN_USER_TMP_DIR` next. If it's set, return that. - Finally, fall back on `/tmp` on Darwin and Linux, and `/data/local/tmp` on Android. Closes apple#2861. Modifications: - Reworks `NIOFileSystem.temporaryDirectory`. Result: - NIOFileSystem will now try `${TMPDIR}` first for the temporary directory. Caveats: - We might want to align how Swift-NIO and FoundationEssentials resolve temp directory, and [FoundationEssentials have a different approach](https://github.com/swiftlang/swift-foundation/blob/9d57f36de757b3d5e3a2f7ffcf27aaec3033509f/Sources/FoundationEssentials/String/String%2BPath.swift#L484-L533). But, I agree with [this comment](apple#2861 (comment)), it feels like TMPDIR is an expected default.
Thanks for this patch! I've asked @glbrntt to review, as he's most familiar with this section of the code. |
Thanks, I prefer this for Android and currently patch this to use Foundation's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the "actual" change looks great. I left a comment on the test though.
let originalTMPDIR = getenv("TMPDIR") | ||
defer { | ||
if let originalTMPDIR { | ||
setenv("TMPDIR", String(cString: originalTMPDIR), 1) | ||
} else { | ||
unsetenv("TMPDIR") | ||
} | ||
} | ||
|
||
let customTmpDir = "/custom/tmp/dir" | ||
setenv("TMPDIR", customTmpDir, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit hesitant to mess around with TMPDIR
like this in case other tests running in parallel are relying on it.
II think my preference here would be to check if TMPDIR
is set and then check fs.temporaryDirectory
if it was set.
Motivation:
This PR aligns what temp directory NIOFileSystem will return first:
${TMPDIR}
as it's an expressed user preference_CS_DARWIN_USER_TMP_DIR
next. If it's set, return that./tmp
on Darwin and Linux, and/data/local/tmp
on Android.Closes #2861.
Modifications:
NIOFileSystem.temporaryDirectory
.Result:
${TMPDIR}
first for the temporary directory.Caveats: