Skip to content
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

canonical-path: add strip_prefix #579

Open
P-E-Meunier opened this issue Dec 15, 2020 · 2 comments
Open

canonical-path: add strip_prefix #579

P-E-Meunier opened this issue Dec 15, 2020 · 2 comments

Comments

@P-E-Meunier
Copy link

Having a checked version of strip_prefix, guaranteed to happen only between two canonical paths, would be very useful.

@tony-iqlusion
Copy link
Member

Can you provide a concrete use case?

To me it seems a bit unusual: where adding to an existing path addresses subtrees, strip_prefix refers to an entirely different subtree of the filesystem, where this crate's goal is to prevent confusion between filesystem subtrees.

@P-E-Meunier
Copy link
Author

In Pijul, we need paths relative to the root of a repository: specifically, when we have a repository in /path/to/my/repo, the current directory is /path/to/my/repo/a/b/c, and we want to add ../d/../f, we need to know that the file to add, relative to the root of the repository, is a/f.

Now, this wasn't a problem on Unix, since the root of the repository is always in canonical form, so I was canonicalizing paths, and then stripping off the root of the repository.

Unfortunately, that doesn't really work on Windows, where canonicalize returns an "extended syntax path", which is almost never used by end users directly, and almost always as a result of calling canonicalize.

I understand that this is a strange use case, since we're essentially implementing a filesystem inside another filesystem, and we can totally do without strip_prefix if you don't think this is relevant (some documentation about that design choice would be useful though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants