Closed imlk0 closed 3 years ago
Document the steps to solve this problem:
The expected behavior:
Causes of this issue:
The reason is similar to the one of the previous issue.
When translating a path, proot-rs needs to create a new path by iterating over the components in the path (with Path::components()
). However, the trailing slash is not shown in the results of Path::components()
, with is a flaw in the implementation of the rust standard library.
https://github.com/rust-lang/rust/issues/29008#issuecomment-153104531
According to POSIX
A pathname that contains at least one non-
character and that ends with one or more trailing characters shall not be resolved successfully unless the last pathname component before the trailing characters names an existing directory or a directory entry that is to be created for a directory immediately after the pathname is resolved. Interfaces using pathname resolution may specify additional constraints1 when a pathname that does not name an existing directory contains at least one non- character and contains one or more trailing characters. If a symbolic link is encountered during pathname resolution, the behavior shall depend on whether the pathname component is at the end of the pathname and on the function being performed. If all of the following are true, then pathname resolution is complete:
- This is the last pathname component of the pathname.
- The pathname has no trailing
. - The function is required to act on the symbolic link itself, or certain arguments direct that the function act on the symbolic link itself.
Something maybe helpful: https://elixir.bootlin.com/linux/latest/source/fs/namei.c#L97
```rust
/* [Feb-Apr 2000 AV] Complete rewrite. Rules for symlinks:
* inside the path - always follow.
* in the last component in creation/removal/renaming - never follow.
* if LOOKUP_FOLLOW passed - follow.
* if the pathname has trailing slashes - follow.
* otherwise - don't follow.
* (applied in that order).
*/
```
Way to fix:
PathBuf
to add two functions:
fn with_trailing_slash(&self) -> bool;
: Check if this path contains trailing slash.try_add_trailing_slash(&mut self);
: Add a trailing slash ("/") to PathBuf.translate_absolute_path()
:
enter()
function of each path related syscalls:
proot-rs is currently not aware of the / at the end of the path during path translation. This causes the behavior of ls to be inconsistent with that on host.
inside guestfs:
in hostfs:
This issue and https://github.com/proot-me/proot-rs/issues/40 are both related to handling trailing slash