-
-
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
[ospaths] fix #8491: XDG_CONFIG_HOME was being ignored due to #8681 + private normalizePathEnd #8680
[ospaths] fix #8491: XDG_CONFIG_HOME was being ignored due to #8681 + private normalizePathEnd #8680
Conversation
/cc @Varriount I'd love to get this merged ASAP as it fixes an annoying bug; thanks! |
|
I can see what you did here and I'm mildly offended. ;-) |
well i mentioned "#8491 XDG_CONFIG_HOME was being happily ignored"; but ok, I just added test case to show the bug in top-level message
the original code had style issues, eg using But ok, I just added a commit to remove some of the excessive UFCS.
ok; made it private for now.
well the other issue was that old code could end up with double trailing DirSep (in both windows and posix); after the PR, this is fixed.
It's right there in the documentation:
I agree with that statement.
not sure I follow; keep in mind this is all volunteer work. Do you want me to CC you in every PR? I could do that; I assumed you may not want to review every single PR, which doesn't scale, and I'm assuming everyone with commit rights is expected to do a good review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at my alternative implementation please.
lib/pure/ospaths.nim
Outdated
else: | ||
# still need to end with `DirSep` for root | ||
if result.len == 0: | ||
result = "" & DirSep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$DirSep
is better style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/pure/ospaths.nim
Outdated
result = "" & DirSep | ||
else: | ||
when doslikeFileSystem: | ||
if result[^1] == ':': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think more correct would be this check if result.len == 2 and result[1] == ':'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/pure/ospaths.nim
Outdated
@@ -449,6 +449,23 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} = | |||
elif defined(posix): | |||
result = path[0] == '/' | |||
|
|||
proc normalizePathEnd(path:string, trailingSep = false): string = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, space after colon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/pure/ospaths.nim
Outdated
## Returns ``path`` with guaranteed 0 or 1 trailing separator, depending on | ||
## ``trailingSep``, and taking care of special case of root paths. | ||
if path.len == 0: return "" | ||
result = strip(path, leading = false, trailing = true, {DirSep, AltSep}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still "meh". How about this:
proc normalizePathEnd(path: var string, trailingSep = false) =
var i = path.len
while i >= 1 and path[i-1] in {DirSep, AltSep}: dec(i)
if trailingSep and i == path.len:
path.add DirSep
else:
path.setLen(i+ord(trailingSep))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this had a few bugs:
normalizePathEnd
should only normalize path end, and should not change whether a path is absolute or relative; the version above could turn "/" into "" or vice versa.
I added test cases to make sure we prevent future regressions) but I reimplemented starting from your version and trying hard to minimize branching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not so much about minimzing branching, it's about avoiding stdlib procs that never quite do the right thing and you are left with the hairy special cases anyway.
Ok, fair enough, the other |
thx, will fix all these this weekend |
As far as correctness is concerned, isn't a path like By "correct" I mean "it works, the OS doesn't care that the slashes are doubled". |
Pretty sure this is the case, however allowing these makes path comparisons much trickier to implement correctly. |
and there are existing bugs related to that: eg just filed #8734 (yes, these will be eventually fixed). But Nim should not introduce new double slashes (in |
b79ac01
to
721cdf8
Compare
721cdf8
to
a2f9c47
Compare
@Araq PTAL |
23d2272
to
d3ba8ae
Compare
sure path endings are normalized with 0 or 1 trailing sep, taking care of edge cases
d3ba8ae
to
90d3611
Compare
'normalizePathEnd' is still the wrong idea. cmpPaths("C://foo/bar", r"C:\foo\bar") --> should be equal |
I just filed #8780 for that yes, What I'm arguing for is that our API's should not introduce new style violation (by that I mean duplicated DirSep): As shown in this PR, getting the details right is tricky, so that's why this PR is needed so the tricky work is handled in just 1 place. |
thanks |
XDG_CONFIG_DIR
env var ignored (prevents disabling ~/.config/nim.cfg for 1 process) #8491 (which is actually still broken:XDG_CONFIG_HOME
was being happily ignored due to a bug in nim:whenwhen Foo
wrongly accepts non-bool Foo #8681), see [1][1] here's the bug:
XDG_CONFIG_HOME
is ignored:XDG_CONFIG_HOME=FOO rnim bugs/compiler/t20_XDG_CONFIG_HOME.nim
nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r bugs/compiler/t20_XDG_CONFIG_HOME.nim
getConfigDir()=/Users/timothee/.config/
bugs/compiler/t20_XDG_CONFIG_HOME.nim: