Getting the path of a Dir
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- rust
- Domain
- operating-systems, security
Research direction
Start by reviewing the existing cap-std Dir APIs and the ProjectDirs methods from cap-directories, then examine how the proposed wrapper tracks paths. Done would require an agreed API and documented capability-model warnings; the issue does not name files or tests to update.
Written by the indexing model from the issue text.
Description
Sometimes I'd like to be able to get the path for a Dir.
For example,
- logs or debugging
- passing the path to a separate process
- passing the path to a library that doesn't yet support the capability model
For example, in a personal project, I'm using the git2 wrapper around libgit2. In order to call Repository::clone(url, path), I need the path of the cache directory. I could use gitoxide, a pure rust implementation of git, however that would have the same problem. Maybe in the future we can make gitoxide use cap-std, but for now that's not an option.
Yes, some of these examples break the capability model, however, from a pragmatic point of view, that may be acceptable.
I'm not sure what the best approach here is, but in my personal project I'm using a wrapper like
pub struct DirWithPath {
dir: Dir,
path: PathBuf,
}
with a constructor like
pub fn open_ambient_dir<P: AsRef<Path>>(path: P, ambient_authority: AmbientAuthority) -> io::Result<Self> {
Dir::open_ambient_dir(path.as_ref(), ambient_authority).map(|dir| Self {
dir,
path: path.as_ref().to_path_buf(),
})
}
and an open_dir method that concatenates the path:
pub fn open_dir<P: AsRef<Path>>(self: &Self, path: P) -> io::Result<Self> {
let full_path = self.path.join(path.as_ref());
self.dir.open_dir(path).map(|dir| Self {
dir,
path: full_path,
})
}
One issue with maintaining my own wrapper is that I can't use e.g ProjectDirs from cap-directories because its methods return Dirs, so the paths are unknown. I would have to wrap directories_next directly.
I wonder if it would be useful for other people if something like this was added to cap-std (with appropriate warnings with respect to it breaking the capability model)?
- Dominant language
- Rust
- Stars
- 821
- Forks
- 59
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bytecodealliance/cap-std
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bytecodealliance/cap-std#427 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
bytecodealliance/cap-std#416 · 2 comments ·
-
Archiving cap-std Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
bytecodealliance/cap-std#426 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
bytecodealliance/cap-std#423 · 5 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
bytecodealliance/cap-std#408 · 4 comments · 2 reactions ·
All issues in bytecodealliance/cap-std
Similar issues
-
bug CLI custom-model
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
rust-bitcoin/rust-bitcoin#6930 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
fulcrumgenomics/ferro-hgvs#2251 ·
-
A-allocators A-docs C-enhancement T-libs
Difficulty 2/5 1-3 hours Newbie friendliness 75/100