Closed roman-holovin closed 5 years ago
As far as I know, canonicalize
doesn't handle ~
, since that is a shell feature. But for relative paths we should be using it, indeed!
Yeah, I think cloudhead is right with regards to resolving the ~
.
I looked into ways of handling that when it was implemented and the dirs::BaseDirs crate seemed to be best choice since it makes gathering OS-wide / user-wide environment paths fairly easy and safe.
That said, I think implementing relative paths shouldn't be too hard, and I see that even std::path::Path supports an official alias to the canonicalize function as well.
I'll make an attempt at this in a branch later tonight.
Oh, I see. I was confused because documentation mentions that canonicalize
uses realpath
to expand paths on Unixes and I tried it in the shell and it worked. I missed the fact that shell expansion happens before command execution. Good to know, thanks.
Canonicalizing the paths required a bit of a rethink of the path parsing logic function, but I have made a PR that (hopefully) handles this well enough.
@cloudhead since this is merged I think this issue could be closed, whenever you have time :)
I have tried to use
~
,..
in paths andrx
is failing to parse those. Also, I suppose it may fail with symlinks also.https://github.com/cloudhead/rx/blob/75a11ff3667d035a3b673c908ee4409c7dc92d7b/src/parser.rs#L218
There is canonicalize function that should be able to resolve paths more reliably.