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

feat(std/node): Add back os.tmpdir() implementation #1308

Merged
merged 1 commit into from Oct 1, 2021
Merged

feat(std/node): Add back os.tmpdir() implementation #1308

merged 1 commit into from Oct 1, 2021

Conversation

espindola
Copy link
Contributor

This was lost when Dino.dir was removed. This implementation is in
typescript and should do the same thing as std::env::temp_dir was
doing in the previous implementation:

https://doc.rust-lang.org/std/env/fn.temp_dir.html

The previous implementation was in the pull request denoland/deno#4213

@CLAassistant
Copy link

CLAassistant commented Sep 24, 2021

CLA assistant check
All committers have signed the CLA.

@kt3k
Copy link
Member

kt3k commented Sep 27, 2021

Thank you for your contribution. But this doesn't seem aligned to the Node.js implementation of os.tmpdir. I'd suggest we should simply follow the node.js implementation https://github.com/nodejs/node/blob/43291b98edaa682b9fa74f95e084ce7a01c85774/lib/os.js#L173-L189

And please sign the CLA

@espindola
Copy link
Contributor Author

Thank you for your contribution. But this doesn't seem aligned to the Node.js implementation of os.tmpdir. I'd suggest we should simply follow the node.js implementation https://github.com/nodejs/node/blob/43291b98edaa682b9fa74f95e084ce7a01c85774/lib/os.js#L173-L189

Done.

And please sign the CLA

There should now be a corporate CLA in place.

return base + "\\temp";
}
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

For readability purposes, use else.

@piscisaureus
Copy link
Member

It seems that node.js strips trailing slashes (and backslashes on windows) unless the temp dir is a root (/ or X:\).
Is there a reason this implementation doesn't?

@espindola
Copy link
Contributor Author

It seems that node.js strips trailing slashes (and backslashes on windows) unless the temp dir is a root (/ or X:\). Is there a reason this implementation doesn't?

Yes, sorry I meant to include that in the comment. The implementation in node removes only one trailing slash:

 $ TMP=/tmp/ node -e 'console.log(os.tmpdir())'
 /tmp
 $ TMP=/tmp// node -e 'console.log(os.tmpdir())'
 /tmp/

Which seems pretty arbitrary. I can do it if we want bug for bug compatibility, but it seems better to remove all trailing slashes or none, no?

@piscisaureus
Copy link
Member

Which seems pretty arbitrary. I can do it if we want bug for bug compatibility, but it seems better to remove all trailing slashes or none, no?

It does seem arbitrary, we should remove all trailing slashes.
On windows we should remove both / and \.

This was lost when Dino.dir was removed. This implementation is in
typescript and unlike the previous implementation, it follows what the
node version does, instead of using rust's std::env::temp_dir.
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@kt3k
Copy link
Member

kt3k commented Oct 1, 2021

@espindola Thank you for your contribution!

@kt3k kt3k merged commit 36a2708 into denoland:main Oct 1, 2021
traceypooh pushed a commit to traceypooh/deno_std that referenced this pull request Nov 14, 2021
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.

None yet

4 participants