Skip to content
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.temporaryDirectory: Consider falling back to TMPDIR #2861

Open
weissi opened this issue Sep 3, 2024 · 5 comments
Open

NIOFileSystem.temporaryDirectory: Consider falling back to TMPDIR #2861

weissi opened this issue Sep 3, 2024 · 5 comments

Comments

@weissi
Copy link
Member

weissi commented Sep 3, 2024

Currently, NIOFS's temporaryDirectory uses _CS_DARWIN_USER_TEMP_DIR on Darwin and /tmp//data/local/tmp anywhere else. I think we should consider the env var TMPDIR if set.

So maybe:

  • Darwin: _CS_DARWIN_USER_TEMP_DIR -> TMPDIR -> /tmp
  • Linux: TMPDIR -> /tmp
  • Android: TMPDIR -> /data/local/tmp
    ?
@glbrntt
Copy link
Contributor

glbrntt commented Sep 3, 2024

That seems pretty reasonable to me. I wonder if TMPDIR should be checked first on Darwin as it's a user-expressed preference?

@weissi
Copy link
Member Author

weissi commented Sep 3, 2024

That seems pretty reasonable to me. I wonder if TMPDIR should be checked first on Darwin as it's a user-expressed preference?

For reference this is what swift-foundation does: https://github.com/apple/swift-foundation/blob/9d57f36de757b3d5e3a2f7ffcf27aaec3033509f/Sources/FoundationEssentials/String/String%2BPath.swift#L484-L533

@vlm
Copy link
Contributor

vlm commented Sep 3, 2024

I would think ${TMPDIR} should be consulted first. The other way around makes limited sense.

Besides the "expressed preference" comment from @glbrntt, there are other considerations:

  • Since _CS_DARWIN_USER_TEMP_DIR might only be unavailable in some extreme circumstances, its reliance on ${TMPDIR} as a fallback is always going to come as a surprise. It can't be relied upon, and if it comes to that that'd be very surprising.
  • In addition to that, consulting ${TMPDIR} first aligns with cross-platform developer's expectations. Swift-on-server is perhaps the swift-nio's most important focus, and this consideration may have correspondingly different weight compared to swift-foundation's.

For completeness, I can also see some arguments for aligning with swift-foundation.

@weissi
Copy link
Member Author

weissi commented Sep 3, 2024

CC @parkera also

@parkera
Copy link
Member

parkera commented Sep 3, 2024

swift-foundation should be able to accommodate both use cases, and it would be nice to have a single implementation of this kind of logic. As you can see from the one we have there already, it is unfortunately not trivial. It's also something which varies dramatically depending on platform, so abstracting it once also makes sense.

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

No branches or pull requests

4 participants