-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
On macOS, os.tmpdir() is not a real path #11422
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
Comments
I think |
To work around: nodejs/node#11422 Fixes #8 I went with resolving the path synchronously and lazily once. It's done sync in the async method too, but only once, so I think that's an ok compromise.
Don't you think
should be an invariant? You would request that we don't return the string that the user/OS has set the temp dir string to, but instead return some other path we derive from it? What if TEMP points a symlink, and they change the symlink, won't an app that called I think setting TEMP to a symlink may be surprising in itself, but node unilaterally deciding the user didin't really mean what they did might be even more surprising. Lines 34 to 52 in a196895
|
No, because that's an implementation detail, and it's already a non-invariant—Your example would fail if the user had |
* Resolve the path to the temp directory To work around: nodejs/node#11422 Fixes #8 I went with resolving the path synchronously and lazily once. It's done sync in the async method too, but only once, so I think that's an ok compromise. * Add a test
One reason why I think this is unlikely to happen is that it would mean changing It's either that or resolve and cache at startup, but then changes to |
I don't think a
The implementation of
It should probably be treated as a breaking change, sure, but returning a real path may make the If that's not a viable direction we should at least document that it may not return a real path, and that this is a known issue on macOS. |
I did a quick survey and both python's
The environment variables and the order they're tried in is fairly standard for UNIX and Windows programs. I'd be okay with having that documented. |
This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that. |
@Trott the documentation around this could be approved. Might be worth keeping the ticket around for that. I just haven't gotten around to it. |
I guess I wouldn't personally object to a doc update, but I don't know about keeping an issue open about it as it seems superfluous too. My reasoning is:
That being stated, as I said before, I personally wouldn't object to adding this information. Just not sure it needs to be an open item and honestly I'm not sure others wouldn't object. |
Can it be re-opened? P.s. Closing issues because they are arbitrarily old doesn't sound like a good idea to me, if the metric to optimize for is the number of issues open one may as well close the issue tracker. |
Are you asking that it be re-opened pending a doc change? Or pending a change in the behavior of
I agree. Fortunately, that's not what happened. It's not that the issue was old. It's that the issue was inactive. meaning that no one was commenting, no one was working on a PR to address it, and the case for doing nothing seems compelling.
The thing to optimize for is to have the contents of the issue tracker be useful and relevant. This means not having a lot of "open" issues for things that aren't going to be addressed. This seemed like it fell into that category. I guess two options that haven't been suggested (or that I've missed, in which case, hey, sorry):
On balance, I'm in favor of doing nothing or maybe updating the docs. I think I'll go open a PR to update the docs now and see what other people think..... |
The issue tracker is useful as a list of things there is a reasonable expectation that someone will work on ("work" being discuss, PR a fix for, investigate, etc.). Its not useful to keep a list of things that people don't like or find surprising about Node.js, but that no one (since July 2017!) has considered important enough to actually do something about. That list would be very long indeed. |
I'm in favor of the proposed behavior change, but if for some reason that can't be done I'd appreciate having the docs reflect this little discrepancy.
Fair enough, but when having lots of open issues it's expected that some of them may not be worked/commented on for a while.
I think a better approach would be to tag these potential abandoned issues with a specific tag and filter that tag out when browsing the open issues, this way people finding this issue could still considering adding their "👍" on it or commenting, signaling that it's something they care about, which they are probably not going to do if the issue is closed, and having issues like this still in the issue tracker shouldn't be a problem as they can be filtered out.
I don't understand what's the problem here, isn't
temp-dir may be that module, it seems fairly popular with ~1.9M weekly downloads and 220k dependents on GitHub.
I agree, if a decision was made that those things won't be changed. For this specific issue though it seems that there was a decision to make about what to do about it, none has been made and the issue was closed. You may argue closing the issue was actually the decision made but that was just a temporary action as the issue is now open again and nothing changed.
This issue is about a very minor detail, but I'd argue if there's an issue being tracked and a decision on what to do about it hasn't been taken yet (not even a "we won't change this") for X years that doesn't mean it shouldn't be tracked anymore. Also this issue has been closed in 2017, perhaps that also discouraged people from commenting on it these past years. Thanks for reopening 👍 |
I indeed meant "asynchronous". Sorry about the error. I have edited the comment to be correct.
I based that on @bnoordhuis's comment above. |
@Trott @bnoordhuis and why not? It would have to be performed under macOS only, and unless the value of I'd personally rather do this than pull a PHP and introduce It doesn't seem too much of a performance burden to me, and popular third-party libraries like |
@fabiosantoscode It seems like a premise in the case you're making is that Node.js should do more than Ruby, Python, Perl, PHP, Java, etc. currently do to smooth out cross-platform differences like this. Is that correct? If so, why is that? (I'm not saying we should or shouldn't. I want to know what your thinking is, though, since you have definite opinions here and I want to understand as fully as I can. Is it that those other languages should do more too? Or is Node.js unique?) |
@Trott I don't care what those other languages are doing because I don't use them, I suppose though that if changing this is Node is for the better other platforms should implement the change too, obviously.
I'm just sharing my opinion regarding a very marginal issue in order to potentially improve a bit a platform I care about, I don't know enough to have definitive opinions on almost anything. Basically this feels inconsistent to me, as a Node user who expects Node to smooth over little differences like this across OS', and it would break things under some scenarios, scenarios that I've never personally encountered though, like: #31877 (comment). If for whatever reason this can't be changed I'd argue this and other similar quirks/behaviors/cross-platform differences should be documented, as stumbling on them even after having read the docs is not great. Just to mention another "quirk" I know of that should be documented too: non-bigint Other than this I don't think I have anything useful to add to the discussion. |
This has nothing to do with me, but since I've been mentioned so many times I'll chip in :) I believe making node code more cross platform by default is important. It's a major selling point for this runtime. As someone who writes libraries on npm for multiple platforms (the most experimental ones just for Linux and Mac) I find it important that the platform layer of this runtime attempts to make things more uniform across platforms. The reason is, that I'm using my own platform, like most people are. Testing on other platforms is cumbersome (even with a CI, given that testing on windows is considerably slower on Travis for example) and I believe I shouldn't have to do it. Node provides a few platform interfaces in the form of functions and objects, which are really nice to use and the community has picked them up and made really cool things with them. It's my belief that these should work uniformly across platforms, and when this is not possible, it should be documented. |
Whoops, sorry about that. the mis-mention was my doing. I need to type more carefully in this issue tracker, clearly. |
No problem :) |
Closing this as there's been no further activity on it. It can be re-opened again if necessary |
On macOS this turns `/tmp` into `/private/<actual directory>`; see this issue from Node.js for someone bringing up the identical problem - nodejs/node#11422
os.tmpdir()
returns a path like/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
. Pernode/lib/os.js
Line 43 in 00c86cc
$TMPDIR
environment variable. However on macOS this is a symlink. The real path is/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
:On the face of it the current behavior seems correct, and it's just macOS that is annoying. On the other hand it makes for surprising failures when writing cross-platform code. See sindresorhus/temp-write#8 for example.
At the very least I think this pitfall should be documented (happy to open a PR), but that just means users need to always wrap
os.tmpdir()
withfs.realpathSync()
. Shouldos.tmpdir()
do this by itself? On macOS only, or all platforms?(Note that this is different from #7545. When your shell is in a directory like
/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T
thenprocess.env.PWD
is correctly set to that path.)The text was updated successfully, but these errors were encountered: