summaryrefslogtreecommitdiff
path: root/runtime/ops/fs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/ops/fs.rs')
-rw-r--r--runtime/ops/fs.rs31
1 files changed, 15 insertions, 16 deletions
diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs
index d1a2489ba..d1242b116 100644
--- a/runtime/ops/fs.rs
+++ b/runtime/ops/fs.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// Some deserializer fields are only used on Unix and Windows build fails without it
-use super::io::std_file_resource;
-use super::io::StreamResource;
+use super::io::StdFileResource;
use crate::fs_util::canonicalize_path;
use crate::permissions::Permissions;
use deno_core::error::bad_resource_id;
@@ -188,7 +187,7 @@ fn op_open_sync(
let (path, open_options) = open_helper(state, args)?;
let std_file = open_options.open(path)?;
let tokio_file = tokio::fs::File::from_std(std_file);
- let resource = StreamResource::fs_file(tokio_file);
+ let resource = StdFileResource::fs_file(tokio_file);
let rid = state.resource_table.add(resource);
Ok(json!(rid))
}
@@ -202,7 +201,7 @@ async fn op_open_async(
let tokio_file = tokio::fs::OpenOptions::from(open_options)
.open(path)
.await?;
- let resource = StreamResource::fs_file(tokio_file);
+ let resource = StdFileResource::fs_file(tokio_file);
let rid = state.borrow_mut().resource_table.add(resource);
Ok(json!(rid))
}
@@ -239,7 +238,7 @@ fn op_seek_sync(
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, AnyError> {
let (rid, seek_from) = seek_helper(args)?;
- let pos = std_file_resource(state, rid, |r| match r {
+ let pos = StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.seek(seek_from).map_err(AnyError::from),
Err(_) => Err(type_error(
"cannot seek on this type of resource".to_string(),
@@ -258,7 +257,7 @@ async fn op_seek_async(
let resource = state
.borrow_mut()
.resource_table
- .get::<StreamResource>(rid)
+ .get::<StdFileResource>(rid)
.ok_or_else(bad_resource_id)?;
if resource.fs_file.is_none() {
@@ -286,7 +285,7 @@ fn op_fdatasync_sync(
) -> Result<Value, AnyError> {
let args: FdatasyncArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
- std_file_resource(state, rid, |r| match r {
+ StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.sync_data().map_err(AnyError::from),
Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
})?;
@@ -304,7 +303,7 @@ async fn op_fdatasync_async(
let resource = state
.borrow_mut()
.resource_table
- .get::<StreamResource>(rid)
+ .get::<StdFileResource>(rid)
.ok_or_else(bad_resource_id)?;
if resource.fs_file.is_none() {
@@ -332,7 +331,7 @@ fn op_fsync_sync(
) -> Result<Value, AnyError> {
let args: FsyncArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
- std_file_resource(state, rid, |r| match r {
+ StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.sync_all().map_err(AnyError::from),
Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
})?;
@@ -350,7 +349,7 @@ async fn op_fsync_async(
let resource = state
.borrow_mut()
.resource_table
- .get::<StreamResource>(rid)
+ .get::<StdFileResource>(rid)
.ok_or_else(bad_resource_id)?;
if resource.fs_file.is_none() {
@@ -379,7 +378,7 @@ fn op_fstat_sync(
super::check_unstable(state, "Deno.fstat");
let args: FstatArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
- let metadata = std_file_resource(state, rid, |r| match r {
+ let metadata = StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.metadata().map_err(AnyError::from),
Err(_) => Err(type_error("cannot stat this type of resource".to_string())),
})?;
@@ -399,7 +398,7 @@ async fn op_fstat_async(
let resource = state
.borrow_mut()
.resource_table
- .get::<StreamResource>(rid)
+ .get::<StdFileResource>(rid)
.ok_or_else(bad_resource_id)?;
if resource.fs_file.is_none() {
@@ -1365,7 +1364,7 @@ fn op_ftruncate_sync(
let args: FtruncateArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let len = args.len as u64;
- std_file_resource(state, rid, |r| match r {
+ StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.set_len(len).map_err(AnyError::from),
Err(_) => Err(type_error("cannot truncate this type of resource")),
})?;
@@ -1385,7 +1384,7 @@ async fn op_ftruncate_async(
let resource = state
.borrow_mut()
.resource_table
- .get::<StreamResource>(rid)
+ .get::<StdFileResource>(rid)
.ok_or_else(bad_resource_id)?;
if resource.fs_file.is_none() {
@@ -1648,7 +1647,7 @@ fn op_futime_sync(
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);
- std_file_resource(state, rid, |r| match r {
+ StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => {
filetime::set_file_handle_times(std_file, Some(atime), Some(mtime))
.map_err(AnyError::from)
@@ -1675,7 +1674,7 @@ async fn op_futime_async(
let resource = state
.borrow_mut()
.resource_table
- .get::<StreamResource>(rid)
+ .get::<StdFileResource>(rid)
.ok_or_else(bad_resource_id)?;
if resource.fs_file.is_none() {