manuel-woelker / rust-vfs

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

Accessing the VfsPath::fs #20

Open der-b opened 3 years ago

der-b commented 3 years ago

I think, I found another issue with the VfsPath.

Let assume, that we want to read some path from a configuration file. Therefore we write a function with a header similar to this:

fn read_path_from_config(config_path: VfsPath) -> VfsResult<VfsPath> {
    // do open the file
    // read path property from config and store it in a String
    let path : String = read_property()?;
    // here we have the problem, that the path is valid in the filesystem in config_path, but we can't access
    // this filesystem and therefore we can't construct a result_path with the type VfsPath, which is in the same 
    // filesystem
    Ok(result_path);
}

It would be possible, to delete the path in config_path by calling parent() until it returns None and than use join to put path into config_path. But I find this wired.

I think, VfsPath is missing some methods to construct a new path from an already existing path to keep the filesystem.

What do you think?

manuel-woelker commented 3 years ago

I am not sure I completely understand.

You could resolve the configured path either relative to the config_path's parent, or some other explicit root or base directory (i.e. using another parameter base_path) via the VfsPath::join() method.

Another option would be to return the path as plain string, and perform the path resolution outside of the config method using the appropriate base or root path there.

If you want to resolve a filesystem absolute path here, that's a bit outside the scope of this crate I think, since it specifically tries to contain everything inside the VFS. You could always create a new PhysicalFS, if that is what is required and the path happens to be absolute.