this post was submitted on 13 Jun 2024
43 points (97.8% liked)

Rust Programming

8168 readers
6 users here now

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] Killing_Spark@feddit.de 2 points 5 months ago (2 children)

I'm not really sure I get the usefulness of this absolute function. It still returns relative paths if the input was relative and it doesn't resolve "..". What would you use it for where canonicalize doesn't work for you?

[–] Ephera@lemmy.ml 2 points 5 months ago (1 children)

Well, as it says in the documentation I linked:

unlike canonicalize absolute does not resolve symlinks and may succeed even if the path does not exist.

Primarily, the latter part is what I want. There's just sometimes situations where a path doesn't exist (yet), but you want to know what it would look like as an absolute path.

[–] taladar@sh.itjust.works 2 points 5 months ago* (last edited 5 months ago)

In 99% of those cases you would want it to resolve .. components though.

[–] ssokolow@lemmy.ml 1 points 5 months ago* (last edited 5 months ago) (1 children)

It still returns relative paths if the input was relative

False

and it doesn’t resolve “…”

I'll assume you meant .., since ... is an ordinary filename. (Aside from the "who remembers ...?" feature introduced in Windows 95's COMMAND.COM where cd ... was shorthand for doing cd .. twice and you could omit the space after cd if your target was all dots.)

The reason it doesn't do that is that, when symlinks get involved, /foo/bar/.. does not necessarily resolve to /foo and making that assumption could introduce a lurking security vulnerability in programs which use it.

[–] Killing_Spark@feddit.de 1 points 5 months ago* (last edited 5 months ago) (1 children)

Hm it seems I misread the documentation there. I know why it doesn't resolve the ".." and that's fine, it just seemed very unnecessary in combination with my flawed understanding of the relative path handling.

Edit: and just to be snarky: I didn't type "..." I typed "..". ;)

[–] ssokolow@lemmy.ml 1 points 5 months ago (1 children)

Edit: and just to be snarky: I didn’t type “…” I typed “…”. ;)

*chuckle* I think Lemmy typed those for you, because I typed three periods and got a Unicode ellipsis, and both of those are also unicode ellipses.

[–] Killing_Spark@feddit.de 1 points 5 months ago (1 children)

Huh that might actually be an issue with your client, mine renders those as two dots

[–] ssokolow@lemmy.ml 2 points 5 months ago

I'm using the web UI, so I'm assuming whatever broad-spectrum Markdown rendering library it uses has smart quote rendering turned on.