-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
relativePath("foo", "foo") is now ".", not "" #13452
Conversation
Not sure I'm buying it. ;-) But anyhow, same story as always:
|
d752b32
to
c2ca192
Compare
it's the same story as in all previous cases where the behavior was corrected (see #13236 (comment), #10018 (comment) and more ) ... here's an example: before PR: # this works, listing files under pwd/changelogs/
for kind, path in walkDir(relativePath(getCurrentDir()/"changelogs", getCurrentDir())):
echo (path,)
# this returned nothing, instead of listing files under `pwd/changelogs/..` = `pwd`
for kind, path in walkDir(relativePath(getCurrentDir()/"changelogs", getCurrentDir()/"changelogs")):
echo (path,) after PR:
done
I've instead added a |
Well tbh I find the behaviour that it doesn't iterate over anything more intuitive.
to see it makes no sense.
For me it's "more weird edge cases". |
|
done, --useVersion now emulates old behavior, simply by defining
it does make sense: change that snippet to it resolves to:
I'm not assuming that, in this context; relative directories are rebasable for relative path manipulations via the usual joinPath etc (which also happens to have a bug see #13455 joinPath("", "") is "/" ; should be "" ; but that's a separate issue) notethis is consistent with go, D, python, and probably more
|
It's terrible but I have to agree. |
df49c9e
to
8839726
Compare
PTAL |
I've thought about this a bit and alternatively we could have changed |
that would break many things
with your proposal it would not work: import os
var dir = getCurrentCompilerExe().parentDir # /pathto/Nim/bin
dir = dir.relativePath(getCurrentDir())
while dir.len > 0:
for ai in walkDir(dir):
echo ("files", dir, ai)
dir = dir.parentDir() under your proposal,
import os
var dir = getCurrentCompilerExe().parentDir
dir = dir.relativePath(getCurrentDir())
let root = "/usr/local"
let dir2 = dir / root
echo (dir2, isAbsolute(dir2))
or you'd also have to change
var path1: string
var path2: RelativeDir # (or AbsoluteDir)
path1.len == 0 has up to now been used to distinguish valid (ie, initialized) paths from invalid path (eg: un-initialized) paths.
if `path1.len == 0` were to have same semantics as `"."`, this would break those assumptions, creating lots of inconsistencies / code breakages
this PR is consistent with D, go, python, C++, which do the right thing here:rdmd --eval 'writeln(relativePath("/baz", "/baz"))' package main . python3 -c 'import os; print(os.path.relpath("/foo","/foo"))' [EDIT]and also C++ for which I just out the relativePath closest equivalent : see https://en.cppreference.com/w/cpp/filesystem/path/lexically_normal |
That's a pretty contrived example though. Not buying it, but I merged your PR already, so the discussion is rather pointless. |
as discussed many times already [1], empty dir shouldn't be considered as a valid dir and not conflated with
"."
, sorelativePath("foo", "foo")
is now"."
andrelativePath("", "foo")
stays""
.[1] see #13236 (comment), #10018 (comment) + other places
parentDir("foo")
is"."
, not""
)