Bug 17488 – Platform-inconsistent behavior from getTempDir()

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-06-10T17:53:34Z
Last change time
2021-10-22T14:55:13Z
Keywords
pull
Assigned to
No Owner
Creator
dlang

Comments

Comment #0 by dlang — 2017-06-10T17:53:34Z
On Windows, std.file's getTempDir() ends with a path separator, but on POSIX it does not. Consistent behaviour would allow cross-platform code to e.g., (if we add the slash to POSIX) simply do "getTempDir() ~ myname.tmp", rather than require checking for the platform. I can do the PR if I know the desired behaviour (add the slash to POSIX or remove it from Windows).
Comment #1 by dlang-bugzilla — 2017-06-10T21:02:31Z
(In reply to dlang from comment #0) > I can do the PR if I know the desired behaviour (add the slash to POSIX or > remove it from Windows). Definitely add it - double slashes will behave the same as a single slash, so adding a slash where existing code also added one will not result in change of behavior. Doing it the other way around is likely to break programs on Windows.
Comment #2 by dlang — 2017-06-11T22:43:01Z
According the the tempDir documentation: On all platforms, tempDir returns "." on failure, representing the current working directory. On failure, the value of getcwd() is returned; on my test (Windows and Ubuntu 14.04) that's the absolute directory, not ".". Should I change the documentation to match the code, or change the code to match the docs?
Comment #3 by dlang-bugzilla — 2017-06-11T22:52:05Z
Hmm, I see it was changed in https://github.com/dlang/phobos/commit/11de397dd7440403df54f84c3674c955c2563fbf#diff-52580fb75b304ba7b04a6b178fe6cdf4L3140 to return getcwd() instead of ".". If there was a reason behind it, it was not specified or documented - that change should not have passed review. CC Joakim, can you shine some light on this? Is that change really needed (and simply undocumented), or was it a stray change we can revert?
Comment #4 by dlang-bugzilla — 2017-06-11T22:57:54Z
OK, I see a rationale in the pull request discussion (https://github.com/dlang/phobos/pull/2150) (should've been in the commit message, BTW): > Android doesn't have a global temp directory and a couple tests fail > if the full path isn't used for the local directory, so I modified > tempDir() to use the full path. The appropriate thing to do at that point would have been to fix the tests instead of changing the behaviour of a public function. However, at this point it's been three years since the change, so today the most sensible course is probably to update the documentation (e.g. saying that the function returns the current directory on failure would not be incorrect for both the old and new behaviour).
Comment #5 by dlang-bugzilla — 2017-06-12T04:12:46Z
Comment #6 by dlang-bot — 2021-10-16T10:58:29Z
@rjframe updated dlang/phobos pull request #5476 "Fix issue 17488: Add trailing slash to POSIX tempDir() to match Windows behaviour" fixing this issue: - Fix Issue 17488 - Add trailing slash to POSIX tempDir() to match Windows behaviour https://github.com/dlang/phobos/pull/5476
Comment #7 by dlang-bot — 2021-10-22T14:55:13Z
dlang/phobos pull request #5476 "Fix issue 17488: Add trailing slash to POSIX tempDir() to match Windows behaviour" was merged into master: - 02f4f148cf4056aa01c6d43d9fcbcaf9c2787f3c by Ryan Frame: Fix Issue 17488 - Add trailing slash to POSIX tempDir() to match Windows behaviour https://github.com/dlang/phobos/pull/5476