bytecodealliance / bytecodealliance/cap-std

Getting the path of a Dir

Offen
#373 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
821
Forks
57
Ø Merge
1 Std. 16 Min.
Gemergte PRs (30 T.)
4

Beschreibung

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

```rust
pub struct DirWithPath {
dir: Dir,
path: PathBuf,
}
```

with a constructor like

```rust
pub fn open_ambient_dir>(path: P, ambient_authority: AmbientAuthority) -> io::Result {
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:

```rust
pub fn open_dir>(self: &Self, path: P) -> io::Result {
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 `Dir`s, 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)?

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Prüfung der vorhandenen cap-std-`Dir`-APIs und der `ProjectDirs`-Methoden aus `cap-directories`, und untersuche anschließend, wie der vorgeschlagene Wrapper Pfade nachverfolgt. Erledigt wäre die Aufgabe mit einer abgestimmten API und dokumentierten Warnungen zum Capability-Modell; das Issue nennt keine zu aktualisierenden Dateien oder Tests.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
operating-systems, security
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.