Skip to content

Implement NSTemporaryDirectory #242

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 3, 2016
Merged

Implement NSTemporaryDirectory #242

merged 1 commit into from
Feb 3, 2016

Conversation

drewcrawford
Copy link
Contributor

No description provided.

@krzyzanowskim
Copy link
Contributor

Temporary directory path may be unique for the user and may differ between operating systems. I'm not sure if it should be hardcoded as "/tmp".

@nubbel
Copy link

nubbel commented Jan 28, 2016

How about $TMPDIR?

@drewcrawford
Copy link
Contributor Author

What does it mean to say that it "may" be per-user?

I know that the Darwin Foundation documentation allows for this to be the case. However FHS 3.17 and IEEE P1003.2 do not; they specify only one temporary directory (well also /var/tmp in the FHS case, but that is unhelpful here).

Darwin's documentation is not sufficiently detailed that we could match the implementation (without someone digging out sourcecode and throwing us a specification). I'm not sure that is what is desired either, since on a standards-conforming Linux/Unix system, /tmp/ is the appropriate directory for all temporary files.

@krzyzanowskim
Copy link
Contributor

@drewcrawford documentation for NSTemporaryDirectory says:

A string containing the path of the temporary directory for the current user. If no such directory is currently available, returns nil.

Swift is not targeted to Darwin solely, as such, in my opinion this value should take environment into consideration when calculate the value.

In particular, NSTemporaryDirectory() on OS X is not "/tmp"

@drewcrawford
Copy link
Contributor Author

I'm not opposed to taking the environment variable into account (it is also a standard) but then we are back to what to do when the environment variable is not set. It is not set in the situation that motivated this patch, and I can confirm that Darwin Foundation still returns a value in that case.

Sent from my iPhone

On Jan 28, 2016, at 7:18 PM, Marcin Krzyzanowski [email protected] wrote:

@drewcrawford documentation for NSTemporaryDirectory says:

A string containing the path of the temporary directory for the current user. If no such directory is currently available, returns nil.

Swift is not targeted to Darwin solely, as such, in my opinion this value should take environment into consideration when calculate the value.

In particular, NSTemporaryDirectory() on OS X is not "/tmp"


Reply to this email directly or view it on GitHub.

@phausler
Copy link
Contributor

phausler commented Feb 1, 2016

Darwin should probably check against confstr using _CS_DARWIN_USER_TEMP_DIR
Then in all platforms check the environment variable TMPDIR
And then fall back to /tmp

That would approximate the behavior of the Darwin version

* Darwin should check against `confstr` using `_CS_DARWIN_USER_TEMP_DIR`
* All platforms check against TMPDIR environment variable
* Fall back to /tmp/
@nubbel
Copy link

nubbel commented Feb 2, 2016

You might also want to take a look at the GNUStep implementation: https://github.com/timburks/gnustep-base/blob/master/Source/NSPathUtilities.m#L1908

@phausler
Copy link
Contributor

phausler commented Feb 2, 2016

@nubbel no need, that implementation looks right on par.
@swift-ci Please test

@krzyzanowskim
Copy link
Contributor

so the docs say:

If no such directory is currently available, returns nil.

can't check ObjC foundation code... just wonder when it should return nil - and if return value should/shouldn't be Optional then.

@phausler Difference to GNUStep implementation is that it return nil if temporary directory does not exists - and that if it can't be created so... it cares about creating new temporary directory if missing or is not writable.

@phausler
Copy link
Contributor

phausler commented Feb 2, 2016

The case of nil is a massive failure internally so my guess is that other things would start to fail if that was a nil return anyhow. Usually in these cases we claim the minuscule edge case failure as making this a non nil return value.

Darwin does not create the directory if it does not exist; we should maintain that behavior. The processes running with Foundation would rarely ever have the privs to actually create /tmp in the first place and we should not be requiring root to call that API.

@phausler
Copy link
Contributor

phausler commented Feb 3, 2016

hmm swift-ci didn't run any tests for this... manual testing shows this works fine

phausler added a commit that referenced this pull request Feb 3, 2016
@phausler phausler merged commit 11a0265 into swiftlang:master Feb 3, 2016
@krzyzanowskim
Copy link
Contributor

@phausler understand. In that case documentation for NSTemporaryDirectory() need update in a way that it not suggest that returned value is usable. From now on developer should check if returned paths is usable for the application.

It's tricky because (I think) for Objective-C it still may return nil value for unusable directory.
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/#//apple_ref/c/func/NSTemporaryDirectory

There is related radar for this: lionheart/openradar-mirror#7356

atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
Improve handling/testing of `filesDependenciesUpdated` for clangd
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Oct 11, 2023
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.

4 participants