summaryrefslogtreecommitdiff
path: root/ext/fs/ops.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-08 11:02:02 -0400
committerGitHub <noreply@github.com>2023-05-08 11:02:02 -0400
commitdf1ca4a158eda08846e11ceb03dd68d6fcffda75 (patch)
treea2c3f2922a3b6326d223e079e3acbedb95048918 /ext/fs/ops.rs
parent0aa2d7c9c16c514e47bbd07ca90552f9159901ef (diff)
refactor(ext/fs): `deno_fs::FileSystem` - conditional `Send + Sync` (#18993)
This allows for having a conditional `Send + Sync` on the file system trait for Deploy.
Diffstat (limited to 'ext/fs/ops.rs')
-rw-r--r--ext/fs/ops.rs96
1 files changed, 46 insertions, 50 deletions
diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs
index c9996d8ce..b866f8645 100644
--- a/ext/fs/ops.rs
+++ b/ext/fs/ops.rs
@@ -7,7 +7,6 @@ use std::io::SeekFrom;
use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;
-use std::sync::Arc;
use deno_core::error::custom_error;
use deno_core::error::type_error;
@@ -28,9 +27,9 @@ use serde::Serialize;
use crate::check_unstable;
use crate::check_unstable2;
+use crate::interface::FileSystemRc;
use crate::interface::FsDirEntry;
use crate::interface::FsFileType;
-use crate::FileSystem;
use crate::FsPermissions;
use crate::OpenOptions;
@@ -39,7 +38,7 @@ pub fn op_cwd<P>(state: &mut OpState) -> Result<String, AnyError>
where
P: FsPermissions + 'static,
{
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let path = fs.cwd()?;
state
.borrow_mut::<P>()
@@ -56,7 +55,7 @@ where
let d = PathBuf::from(&directory);
state.borrow_mut::<P>().check_read(&d, "Deno.chdir()")?;
state
- .borrow::<Arc<dyn FileSystem>>()
+ .borrow::<FileSystemRc>()
.chdir(&d)
.context_path("chdir", &d)
}
@@ -66,10 +65,7 @@ fn op_umask(state: &mut OpState, mask: Option<u32>) -> Result<u32, AnyError>
where
{
check_unstable(state, "Deno.umask");
- state
- .borrow::<Arc<dyn FileSystem>>()
- .umask(mask)
- .context("umask")
+ state.borrow::<FileSystemRc>().umask(mask).context("umask")
}
#[op]
@@ -87,7 +83,7 @@ where
let permissions = state.borrow_mut::<P>();
permissions.check(&options, &path, "Deno.openSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let file = fs.open_sync(&path, options).context_path("open", &path)?;
let rid = state
@@ -112,7 +108,7 @@ where
let mut state = state.borrow_mut();
let permissions = state.borrow_mut::<P>();
permissions.check(&options, &path, "Deno.open()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
let file = fs
.open_async(path.clone(), options)
@@ -144,7 +140,7 @@ where
.borrow_mut::<P>()
.check_write(&path, "Deno.mkdirSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.mkdir_sync(&path, recursive, mode)
.context_path("mkdir", &path)?;
@@ -168,7 +164,7 @@ where
let fs = {
let mut state = state.borrow_mut();
state.borrow_mut::<P>().check_write(&path, "Deno.mkdir()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.mkdir_async(path.clone(), recursive, mode)
@@ -191,7 +187,7 @@ where
state
.borrow_mut::<P>()
.check_write(&path, "Deno.chmodSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.chmod_sync(&path, mode).context_path("chmod", &path)?;
Ok(())
}
@@ -209,7 +205,7 @@ where
let fs = {
let mut state = state.borrow_mut();
state.borrow_mut::<P>().check_write(&path, "Deno.chmod()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.chmod_async(path.clone(), mode)
.await
@@ -231,7 +227,7 @@ where
state
.borrow_mut::<P>()
.check_write(&path, "Deno.chownSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.chown_sync(&path, uid, gid)
.context_path("chown", &path)?;
Ok(())
@@ -251,7 +247,7 @@ where
let fs = {
let mut state = state.borrow_mut();
state.borrow_mut::<P>().check_write(&path, "Deno.chown()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.chown_async(path.clone(), uid, gid)
.await
@@ -274,7 +270,7 @@ where
.borrow_mut::<P>()
.check_write(&path, "Deno.removeSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.remove_sync(&path, recursive)
.context_path("remove", &path)?;
@@ -297,7 +293,7 @@ where
state
.borrow_mut::<P>()
.check_write(&path, "Deno.remove()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.remove_async(path.clone(), recursive)
@@ -323,7 +319,7 @@ where
permissions.check_read(&from, "Deno.copyFileSync()")?;
permissions.check_write(&to, "Deno.copyFileSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.copy_file_sync(&from, &to)
.context_two_path("copy", &from, &to)?;
@@ -347,7 +343,7 @@ where
let permissions = state.borrow_mut::<P>();
permissions.check_read(&from, "Deno.copyFile()")?;
permissions.check_write(&to, "Deno.copyFile()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.copy_file_async(from.clone(), to.clone())
@@ -370,7 +366,7 @@ where
state
.borrow_mut::<P>()
.check_read(&path, "Deno.statSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let stat = fs.stat_sync(&path).context_path("stat", &path)?;
let serializable_stat = SerializableStat::from(stat);
serializable_stat.write(stat_out_buf);
@@ -390,7 +386,7 @@ where
let mut state = state.borrow_mut();
let permissions = state.borrow_mut::<P>();
permissions.check_read(&path, "Deno.stat()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
let stat = fs
.stat_async(path.clone())
@@ -412,7 +408,7 @@ where
state
.borrow_mut::<P>()
.check_read(&path, "Deno.lstatSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let stat = fs.lstat_sync(&path).context_path("lstat", &path)?;
let serializable_stat = SerializableStat::from(stat);
serializable_stat.write(stat_out_buf);
@@ -432,7 +428,7 @@ where
let mut state = state.borrow_mut();
let permissions = state.borrow_mut::<P>();
permissions.check_read(&path, "Deno.lstat()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
let stat = fs
.lstat_async(path.clone())
@@ -451,7 +447,7 @@ where
{
let path = PathBuf::from(path);
- let fs = state.borrow::<Arc<dyn FileSystem>>().clone();
+ let fs = state.borrow::<FileSystemRc>().clone();
let permissions = state.borrow_mut::<P>();
permissions.check_read(&path, "Deno.realPathSync()")?;
if path.is_relative() {
@@ -478,7 +474,7 @@ where
let fs;
{
let mut state = state.borrow_mut();
- fs = state.borrow::<Arc<dyn FileSystem>>().clone();
+ fs = state.borrow::<FileSystemRc>().clone();
let permissions = state.borrow_mut::<P>();
permissions.check_read(&path, "Deno.realPath()")?;
if path.is_relative() {
@@ -508,7 +504,7 @@ where
.borrow_mut::<P>()
.check_read(&path, "Deno.readDirSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let entries = fs.read_dir_sync(&path).context_path("readdir", &path)?;
Ok(entries)
@@ -529,7 +525,7 @@ where
state
.borrow_mut::<P>()
.check_read(&path, "Deno.readDir()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
let entries = fs
@@ -557,7 +553,7 @@ where
permissions.check_write(&oldpath, "Deno.renameSync()")?;
permissions.check_write(&newpath, "Deno.renameSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.rename_sync(&oldpath, &newpath)
.context_two_path("rename", &oldpath, &newpath)?;
@@ -582,7 +578,7 @@ where
permissions.check_read(&oldpath, "Deno.rename()")?;
permissions.check_write(&oldpath, "Deno.rename()")?;
permissions.check_write(&newpath, "Deno.rename()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.rename_async(oldpath.clone(), newpath.clone())
@@ -610,7 +606,7 @@ where
permissions.check_read(&newpath, "Deno.linkSync()")?;
permissions.check_write(&newpath, "Deno.linkSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.link_sync(&oldpath, &newpath)
.context_two_path("link", &oldpath, &newpath)?;
@@ -636,7 +632,7 @@ where
permissions.check_write(&oldpath, "Deno.link()")?;
permissions.check_read(&newpath, "Deno.link()")?;
permissions.check_write(&newpath, "Deno.link()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.link_async(oldpath.clone(), newpath.clone())
@@ -663,7 +659,7 @@ where
permissions.check_write_all("Deno.symlinkSync()")?;
permissions.check_read_all("Deno.symlinkSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.symlink_sync(&oldpath, &newpath, file_type)
.context_two_path("symlink", &oldpath, &newpath)?;
@@ -688,7 +684,7 @@ where
let permissions = state.borrow_mut::<P>();
permissions.check_write_all("Deno.symlink()")?;
permissions.check_read_all("Deno.symlink()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.symlink_async(oldpath.clone(), newpath.clone(), file_type)
@@ -712,7 +708,7 @@ where
.borrow_mut::<P>()
.check_read(&path, "Deno.readLink()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let target = fs.read_link_sync(&path).context_path("readlink", &path)?;
let target_string = path_into_string(target.into_os_string())?;
@@ -734,7 +730,7 @@ where
state
.borrow_mut::<P>()
.check_read(&path, "Deno.readLink()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
let target = fs
@@ -760,7 +756,7 @@ where
.borrow_mut::<P>()
.check_write(&path, "Deno.truncateSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.truncate_sync(&path, len)
.context_path("truncate", &path)?;
@@ -783,7 +779,7 @@ where
state
.borrow_mut::<P>()
.check_write(&path, "Deno.truncate()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.truncate_async(path.clone(), len)
@@ -809,7 +805,7 @@ where
state.borrow_mut::<P>().check_write(&path, "Deno.utime()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.utime_sync(&path, atime_secs, atime_nanos, mtime_secs, mtime_nanos)
.context_path("utime", &path)?;
@@ -833,7 +829,7 @@ where
let fs = {
let mut state = state.borrow_mut();
state.borrow_mut::<P>().check_write(&path, "Deno.utime()")?;
- state.borrow::<Arc<dyn FileSystem>>().clone()
+ state.borrow::<FileSystemRc>().clone()
};
fs.utime_async(
@@ -997,11 +993,11 @@ where
fn make_temp_check_sync<P>(
state: &mut OpState,
dir: Option<String>,
-) -> Result<(PathBuf, Arc<dyn FileSystem>), AnyError>
+) -> Result<(PathBuf, FileSystemRc), AnyError>
where
P: FsPermissions + 'static,
{
- let fs = state.borrow::<Arc<dyn FileSystem>>().clone();
+ let fs = state.borrow::<FileSystemRc>().clone();
let dir = match dir {
Some(dir) => {
let dir = PathBuf::from(dir);
@@ -1026,12 +1022,12 @@ where
fn make_temp_check_async<P>(
state: Rc<RefCell<OpState>>,
dir: Option<String>,
-) -> Result<(PathBuf, Arc<dyn FileSystem>), AnyError>
+) -> Result<(PathBuf, FileSystemRc), AnyError>
where
P: FsPermissions + 'static,
{
let mut state = state.borrow_mut();
- let fs = state.borrow::<Arc<dyn FileSystem>>().clone();
+ let fs = state.borrow::<FileSystemRc>().clone();
let dir = match dir {
Some(dir) => {
let dir = PathBuf::from(dir);
@@ -1089,7 +1085,7 @@ where
let options = OpenOptions::write(create, append, create_new, mode);
permissions.check(&options, &path, "Deno.writeFileSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
fs.write_file_sync(&path, options, &data)
.context_path("writefile", &path)?;
@@ -1121,7 +1117,7 @@ where
permissions.check(&options, &path, "Deno.writeFile()")?;
let cancel_handle = cancel_rid
.and_then(|rid| state.resource_table.get::<CancelHandle>(rid).ok());
- (state.borrow::<Arc<dyn FileSystem>>().clone(), cancel_handle)
+ (state.borrow::<FileSystemRc>().clone(), cancel_handle)
};
let fut = fs.write_file_async(path.clone(), options, data.to_vec());
@@ -1154,7 +1150,7 @@ where
let permissions = state.borrow_mut::<P>();
permissions.check_read(&path, "Deno.readFileSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let buf = fs.read_file_sync(&path).context("readfile")?;
Ok(buf.into())
@@ -1177,7 +1173,7 @@ where
permissions.check_read(&path, "Deno.readFile()")?;
let cancel_handle = cancel_rid
.and_then(|rid| state.resource_table.get::<CancelHandle>(rid).ok());
- (state.borrow::<Arc<dyn FileSystem>>().clone(), cancel_handle)
+ (state.borrow::<FileSystemRc>().clone(), cancel_handle)
};
let fut = fs.read_file_async(path.clone());
@@ -1210,7 +1206,7 @@ where
let permissions = state.borrow_mut::<P>();
permissions.check_read(&path, "Deno.readFileSync()")?;
- let fs = state.borrow::<Arc<dyn FileSystem>>();
+ let fs = state.borrow::<FileSystemRc>();
let buf = fs.read_file_sync(&path).context("readfile")?;
Ok(string_from_utf8_lossy(buf))
@@ -1233,7 +1229,7 @@ where
permissions.check_read(&path, "Deno.readFile()")?;
let cancel_handle = cancel_rid
.and_then(|rid| state.resource_table.get::<CancelHandle>(rid).ok());
- (state.borrow::<Arc<dyn FileSystem>>().clone(), cancel_handle)
+ (state.borrow::<FileSystemRc>().clone(), cancel_handle)
};
let fut = fs.read_file_async(path.clone());