summaryrefslogtreecommitdiff
path: root/ext/fs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-28 08:50:16 -0400
committerGitHub <noreply@github.com>2024-09-28 08:50:16 -0400
commit1bb47805d6331ad048bd5e7ea2581aa230e8fc93 (patch)
tree7f8707f40415e26530f6e6ccd5cde86b22903163 /ext/fs
parentfc739dc5eb2769e4608ccf08d23ca8ff0fcc19c5 (diff)
refactor: move NpmCacheDir to deno_cache_dir (#25916)
Part of the ongoing work to move more of Deno's resolution out of the CLI crate (for use in Wasm and other things) Includes: * https://github.com/denoland/deno_cache_dir/pull/60
Diffstat (limited to 'ext/fs')
-rw-r--r--ext/fs/in_memory_fs.rs8
-rw-r--r--ext/fs/interface.rs10
-rw-r--r--ext/fs/ops.rs12
-rw-r--r--ext/fs/std_fs.rs8
4 files changed, 23 insertions, 15 deletions
diff --git a/ext/fs/in_memory_fs.rs b/ext/fs/in_memory_fs.rs
index 269202386..e29b9d50c 100644
--- a/ext/fs/in_memory_fs.rs
+++ b/ext/fs/in_memory_fs.rs
@@ -44,7 +44,7 @@ impl InMemoryFs {
pub fn setup_text_files(&self, files: Vec<(String, String)>) {
for (path, text) in files {
let path = PathBuf::from(path);
- self.mkdir_sync(path.parent().unwrap(), true, 0).unwrap();
+ self.mkdir_sync(path.parent().unwrap(), true, None).unwrap();
self
.write_file_sync(
&path,
@@ -101,7 +101,7 @@ impl FileSystem for InMemoryFs {
&self,
path: &Path,
recursive: bool,
- _mode: u32,
+ _mode: Option<u32>,
) -> FsResult<()> {
let path = normalize_path(path);
@@ -119,7 +119,7 @@ impl FileSystem for InMemoryFs {
},
None => {
if recursive {
- self.mkdir_sync(parent, true, 0)?;
+ self.mkdir_sync(parent, true, None)?;
} else {
return Err(FsError::Io(Error::new(
ErrorKind::NotFound,
@@ -149,7 +149,7 @@ impl FileSystem for InMemoryFs {
&self,
path: PathBuf,
recursive: bool,
- mode: u32,
+ mode: Option<u32>,
) -> FsResult<()> {
self.mkdir_sync(&path, recursive, mode)
}
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs
index af4beb248..73333b0fd 100644
--- a/ext/fs/interface.rs
+++ b/ext/fs/interface.rs
@@ -121,13 +121,17 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync {
access_check: Option<AccessCheckCb<'a>>,
) -> FsResult<Rc<dyn File>>;
- fn mkdir_sync(&self, path: &Path, recursive: bool, mode: u32)
- -> FsResult<()>;
+ fn mkdir_sync(
+ &self,
+ path: &Path,
+ recursive: bool,
+ mode: Option<u32>,
+ ) -> FsResult<()>;
async fn mkdir_async(
&self,
path: PathBuf,
recursive: bool,
- mode: u32,
+ mode: Option<u32>,
) -> FsResult<()>;
fn chmod_sync(&self, path: &Path, mode: u32) -> FsResult<()>;
diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs
index 150d3b955..b13d3a7d1 100644
--- a/ext/fs/ops.rs
+++ b/ext/fs/ops.rs
@@ -197,7 +197,7 @@ where
.check_write(&path, "Deno.mkdirSync()")?;
let fs = state.borrow::<FileSystemRc>();
- fs.mkdir_sync(&path, recursive, mode)
+ fs.mkdir_sync(&path, recursive, Some(mode))
.context_path("mkdir", &path)?;
Ok(())
@@ -221,7 +221,7 @@ where
(state.borrow::<FileSystemRc>().clone(), path)
};
- fs.mkdir_async(path.clone(), recursive, mode)
+ fs.mkdir_async(path.clone(), recursive, Some(mode))
.await
.context_path("mkdir", &path)?;
@@ -886,7 +886,7 @@ where
const MAX_TRIES: u32 = 10;
for _ in 0..MAX_TRIES {
let path = tmp_name(&mut rng, &dir, prefix.as_deref(), suffix.as_deref())?;
- match fs.mkdir_sync(&path, false, 0o700) {
+ match fs.mkdir_sync(&path, false, Some(0o700)) {
Ok(_) => {
// PERMISSIONS: ensure the absolute path is not leaked
let path = strip_dir_prefix(&dir, dir_arg.as_deref(), path)?;
@@ -928,7 +928,11 @@ where
const MAX_TRIES: u32 = 10;
for _ in 0..MAX_TRIES {
let path = tmp_name(&mut rng, &dir, prefix.as_deref(), suffix.as_deref())?;
- match fs.clone().mkdir_async(path.clone(), false, 0o700).await {
+ match fs
+ .clone()
+ .mkdir_async(path.clone(), false, Some(0o700))
+ .await
+ {
Ok(_) => {
// PERMISSIONS: ensure the absolute path is not leaked
let path = strip_dir_prefix(&dir, dir_arg.as_deref(), path)?;
diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs
index 443c26819..41a8569ba 100644
--- a/ext/fs/std_fs.rs
+++ b/ext/fs/std_fs.rs
@@ -101,7 +101,7 @@ impl FileSystem for RealFs {
&self,
path: &Path,
recursive: bool,
- mode: u32,
+ mode: Option<u32>,
) -> FsResult<()> {
mkdir(path, recursive, mode)
}
@@ -109,7 +109,7 @@ impl FileSystem for RealFs {
&self,
path: PathBuf,
recursive: bool,
- mode: u32,
+ mode: Option<u32>,
) -> FsResult<()> {
spawn_blocking(move || mkdir(&path, recursive, mode)).await?
}
@@ -407,11 +407,11 @@ impl FileSystem for RealFs {
}
}
-fn mkdir(path: &Path, recursive: bool, mode: u32) -> FsResult<()> {
+fn mkdir(path: &Path, recursive: bool, mode: Option<u32>) -> FsResult<()> {
let mut builder = fs::DirBuilder::new();
builder.recursive(recursive);
#[cfg(unix)]
- {
+ if let Some(mode) = mode {
use std::os::unix::fs::DirBuilderExt;
builder.mode(mode);
}