Skip to content

untangle std.fs.path.resolve from the current working directory #13613

Closed

Description

@andrewrk

std.fs.path.resolve is trying to do too much at once, and it results in a leaky abstraction. It can be a nice substitute for realpath when trying to avoid this syscall, however, it suffers from not taking symlinks into account, as well as asking the OS for the cwd unnecessarily.

I propose to change it to be purely a string manipulation function and lose the ability to call cwd().

Any callsites that break from this change should be audited for potential pre-existing bugs.

Activity

  1. added
    enhancement
    breaking
    standard library
    proposal
    on Nov 20, 2022
  2. added this to the 0.12.0 milestone on Nov 20, 2022
  3. kubkon commented on Nov 20, 2022

    @kubkon
    Member

    Not putting an enormous amount of thought into that, I agree. Unless I am misunderstanding the proposal, it would also make for a safer API since without asking the OS for CWD, there is nothing to escape from with ../../ or similar. I also take it, the new function would also not resolve symlinks as it requires inquiring the OS, correct?

  4. andrewrk commented on Nov 20, 2022

    @andrewrk
    MemberAuthor

    The status quo function also does not resolve symlinks. The only syscall status quo does is getcwd(). This proposal would reduce it from that one syscall to none.

  5. kubkon commented on Nov 20, 2022

    @kubkon
    Member

    The status quo function also does not resolve symlinks. The only syscall status quo does is getcwd(). This proposal would reduce it from that one syscall to none.

    So I understood correctly, and I am in favour FWIW.

  6. added a commit that references this issue on Nov 20, 2022
    34223ad
  7. added
    accepted
    on Nov 20, 2022
  8. added 5 commits that reference this issue on Nov 20, 2022
    a0f0b10
    77fe2a3
    ee77378
    2518779
    d24aaf8
  9. matu3ba commented on Nov 23, 2022

    @matu3ba
    Contributor

    Could be extra mentioned:

      1. resolvePosix called on windows can't use getCwd is resolved for WSL.
      1. wasi paths work
  10. modified the milestones: 0.12.0, 0.11.0 on Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedbreakingenhancementproposalstandard library

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions