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

FR: Add path() method to DirEntry #6

Open
netthier opened this issue Sep 27, 2023 · 3 comments
Open

FR: Add path() method to DirEntry #6

netthier opened this issue Sep 27, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@netthier
Copy link

I noticed that russh_sftp::client::fs::DirEntry is missing a path() method which is provided in the std-equivalent.
Would it be possible to add one?

@AspectUnk AspectUnk added the enhancement New feature or request label Sep 28, 2023
@AspectUnk
Copy link
Owner

AspectUnk commented Sep 28, 2023

Welcome! Implementing path() creates a path canonicalization issue, path() returns the full path, and the requested one can be relative. Is it required to do request to the server for canonize the path or do it locally? It is also worth considering the problems of local canonicalization because of which even standard canonicalization checks the path.

@AspectUnk
Copy link
Owner

@chipsenkbeil if it’s not difficult, what you think?

@chipsenkbeil
Copy link

chipsenkbeil commented Sep 28, 2023

@AspectUnk to my knowledge, std::fs::DirEntry::path() does not do any canonicalization or path resolution. Instead, it just prepends the path used to create the entry. This means that if you called read_dir with ./some/relative/path and the entry was file.txt, I would expect path() to return ./some/relative/path/file.txt.

Of course, the trick with the string is knowing what separator to use when joining them together. I do this by first executing and caching a call to the server to see if it's Windows using my homegrown is_windows function.

As for the return type, similar to my comments about using AsRef<Path>, I'd recommend either returning a String or a path abstraction that is separate from Rust's standard path.

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

No branches or pull requests

3 participants