manuel-woelker / rust-vfs

A virtual filesystem for Rust
Apache License 2.0
384 stars 44 forks source link

VfsPath::join(): treat '..' at root as valid #41

Closed Property404 closed 2 years ago

Property404 commented 2 years ago

In unix systems, trying to access the parent of root will return root. This commit implements that behavior.

manuel-woelker commented 2 years ago

Thanks for the PR, although I am not quite sure this would be the expected behaviour. AFAICT the parent of the root being the root is a result of making the implementation of paths simpler, by enforcing every path having a parent.

This change would cause internal inconsistencies since currently root.parent() == None.

Navigating to ".." from root is probably an error or at least not intended. I'd rather have a proper Error when resolving such paths. To better understand the use case, do you have any concrete examples where this behaviour might be useful?

Property404 commented 2 years ago

My use case is that I use VFS to emulate a unix-like system, and the current behavior causes unexpected results

Quote from Stackoverflow: "While it may seem seem more logical to throw an error, this behavior allows all directories to be treated the same rather than having to treat the root directory as a special case."

And I think that makes sense, at least for what I'm doing. But I'm not sure what other people are using this crate for

Property404 commented 2 years ago

Added a fixup! for the VfsPath::parent() issue

Property404 commented 2 years ago

Fixed doc comment and squashed/rebased