Stop returning NOTCAPABLE errors from WASI calls. (#4666)

* Stop returning `NOTCAPABLE` errors from WASI calls.

`ENOTCAPABLE` was an error code that is used as part of the rights
system, from CloudABI. There is a set of flags associated with each file
descriptor listing which operations can be performed with the file
descriptor, and if an attempt is made to perform an operation with a
file descriptor that isn't permitted by its rights flags, it fails with
`ENOTCAPABLE`.

WASI is removing the rights system. For example, WebAssembly/wasi-libc#294
removed support for translating `ENOTCAPABLE` into POSIX error codes, on
the assumption that engines should stop using it.

So as another step to migrating away from the rights system, remove uses
of the `ENOTCAPABLE` error.

* Update crates/wasi-common/src/file.rs

Co-authored-by: Jamey Sharp <jamey@minilop.net>

* Update crates/wasi-common/src/dir.rs

Co-authored-by: Jamey Sharp <jamey@minilop.net>

Co-authored-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
Dan Gohman
2022-08-10 13:44:23 -07:00
committed by GitHub
parent be36dd6b1e
commit 918debfe59
6 changed files with 30 additions and 9 deletions

View File

@@ -76,15 +76,23 @@ impl DirEntry {
if self.caps.contains(caps) {
Ok(())
} else {
Err(Error::not_capable().context(format!("desired {:?}, has {:?}", caps, self.caps,)))
let missing = caps & !self.caps;
let err = if missing.intersects(DirCaps::READDIR) {
Error::not_dir()
} else {
Error::perm()
};
Err(err.context(format!("desired rights {:?}, has {:?}", caps, self.caps)))
}
}
pub fn capable_of_file(&self, caps: FileCaps) -> Result<(), Error> {
if self.file_caps.contains(caps) {
Ok(())
} else {
Err(Error::not_capable()
.context(format!("desired {:?}, has {:?}", caps, self.file_caps)))
Err(Error::perm().context(format!(
"desired rights {:?}, has {:?}",
caps, self.file_caps
)))
}
}
pub fn drop_caps_to(&mut self, caps: DirCaps, file_caps: FileCaps) -> Result<(), Error> {