summaryrefslogtreecommitdiff
path: root/ext/io/lib.rs
diff options
context:
space:
mode:
authorIgor Zinkovsky <igor@deno.com>2023-04-28 12:16:17 -0700
committerGitHub <noreply@github.com>2023-04-28 12:16:17 -0700
commit10ae5ee26557107b22524b1a84ebb56ed7d23fb4 (patch)
treefb5388dff1531a6ac692bb52387697adc39d14b3 /ext/io/lib.rs
parent6369098ad74a263e461478f94782bc469de15468 (diff)
fix(ext/io) several sync fs fixes (#18886)
2 fixes related to sync fs: * update the 2 sync methods on `Resource` trait to take `Rc<Self>` (consistent with other methods) * fix a bug in `StdFileResource::with_inner_and_metadata`, which currently can trigger a panic if a sync method is called on a file with a pending async operation. This could happen in the code path where `File::try_clone` [fails](https://github.com/denoland/deno/blob/39ece1fe0ddacc2cbf182403c9e7085bc01df5a6/ext/io/lib.rs#L485-L489).
Diffstat (limited to 'ext/io/lib.rs')
-rw-r--r--ext/io/lib.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/ext/io/lib.rs b/ext/io/lib.rs
index c85b4baf6..23c087e16 100644
--- a/ext/io/lib.rs
+++ b/ext/io/lib.rs
@@ -461,13 +461,13 @@ impl StdFileResource {
) -> Result<TResult, E>,
) -> Option<Result<TResult, E>> {
match self.cell.try_borrow_mut() {
- Ok(mut cell) => {
+ Ok(mut cell) if cell.is_some() => {
let mut file = cell.take().unwrap();
let result = action(&mut file.inner, &file.meta_data);
cell.replace(file);
Some(result)
}
- Err(_) => None,
+ _ => None,
}
}
@@ -537,14 +537,14 @@ impl StdFileResource {
.await
}
- fn read_byob_sync(&self, buf: &mut [u8]) -> Result<usize, AnyError> {
+ fn read_byob_sync(self: Rc<Self>, buf: &mut [u8]) -> Result<usize, AnyError> {
self
.with_inner_and_metadata(|inner, _| inner.read(buf))
.ok_or_else(resource_unavailable)?
.map_err(Into::into)
}
- fn write_sync(&self, data: &[u8]) -> Result<usize, AnyError> {
+ fn write_sync(self: Rc<Self>, data: &[u8]) -> Result<usize, AnyError> {
self
.with_inner_and_metadata(|inner, _| inner.write_and_maybe_flush(data))
.ok_or_else(resource_unavailable)?
@@ -694,12 +694,15 @@ impl Resource for StdFileResource {
Box::pin(StdFileResource::write_all(self, view))
}
- fn write_sync(&self, data: &[u8]) -> Result<usize, deno_core::anyhow::Error> {
+ fn write_sync(
+ self: Rc<Self>,
+ data: &[u8],
+ ) -> Result<usize, deno_core::anyhow::Error> {
StdFileResource::write_sync(self, data)
}
fn read_byob_sync(
- &self,
+ self: Rc<Self>,
data: &mut [u8],
) -> Result<usize, deno_core::anyhow::Error> {
StdFileResource::read_byob_sync(self, data)