summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/cache/disk_cache.rs4
-rw-r--r--cli/cache/mod.rs4
-rw-r--r--cli/npm/managed/resolvers/local.rs4
-rw-r--r--cli/util/fs.rs8
4 files changed, 13 insertions, 7 deletions
diff --git a/cli/cache/disk_cache.rs b/cli/cache/disk_cache.rs
index 3aeebbc6d..2fee1efe0 100644
--- a/cli/cache/disk_cache.rs
+++ b/cli/cache/disk_cache.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use super::CACHE_PERM;
-use crate::util::fs::atomic_write_file;
+use crate::util::fs::atomic_write_file_with_retries;
use deno_cache_dir::url_to_filename;
use deno_core::url::Host;
@@ -120,7 +120,7 @@ impl DiskCache {
pub fn set(&self, filename: &Path, data: &[u8]) -> std::io::Result<()> {
let path = self.location.join(filename);
- atomic_write_file(&path, data, CACHE_PERM)
+ atomic_write_file_with_retries(&path, data, CACHE_PERM)
}
}
diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs
index a8c60e97a..64d046c15 100644
--- a/cli/cache/mod.rs
+++ b/cli/cache/mod.rs
@@ -7,7 +7,7 @@ use crate::file_fetcher::FetchOptions;
use crate::file_fetcher::FileFetcher;
use crate::file_fetcher::FileOrRedirect;
use crate::npm::CliNpmResolver;
-use crate::util::fs::atomic_write_file;
+use crate::util::fs::atomic_write_file_with_retries;
use deno_ast::MediaType;
use deno_core::futures;
@@ -74,7 +74,7 @@ impl deno_cache_dir::DenoCacheEnv for RealDenoCacheEnv {
path: &Path,
bytes: &[u8],
) -> std::io::Result<()> {
- atomic_write_file(path, bytes, CACHE_PERM)
+ atomic_write_file_with_retries(path, bytes, CACHE_PERM)
}
fn modified(&self, path: &Path) -> std::io::Result<Option<SystemTime>> {
diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs
index 4243d04f2..e93d400e1 100644
--- a/cli/npm/managed/resolvers/local.rs
+++ b/cli/npm/managed/resolvers/local.rs
@@ -17,7 +17,7 @@ use std::sync::Arc;
use crate::cache::CACHE_PERM;
use crate::npm::cache_dir::mixed_case_package_name_decode;
-use crate::util::fs::atomic_write_file;
+use crate::util::fs::atomic_write_file_with_retries;
use crate::util::fs::canonicalize_path_maybe_not_exists_with_fs;
use crate::util::fs::clone_dir_recursive;
use crate::util::fs::symlink_dir;
@@ -550,7 +550,7 @@ impl SetupCache {
}
bincode::serialize(&self.current).ok().and_then(|data| {
- atomic_write_file(&self.file_path, data, CACHE_PERM).ok()
+ atomic_write_file_with_retries(&self.file_path, data, CACHE_PERM).ok()
});
true
}
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index 5adb777b0..f33368d1a 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -32,6 +32,12 @@ use crate::util::progress_bar::ProgressBar;
use crate::util::progress_bar::ProgressBarStyle;
use crate::util::progress_bar::ProgressMessagePrompt;
+/// Writes the file to the file system at a temporary path, then
+/// renames it to the destination in a single sys call in order
+/// to never leave the file system in a corrupted state.
+///
+/// This also handles creating the directory if a NotFound error
+/// occurs.
pub fn atomic_write_file_with_retries<T: AsRef<[u8]>>(
file_path: &Path,
data: T,
@@ -60,7 +66,7 @@ pub fn atomic_write_file_with_retries<T: AsRef<[u8]>>(
///
/// This also handles creating the directory if a NotFound error
/// occurs.
-pub fn atomic_write_file<T: AsRef<[u8]>>(
+fn atomic_write_file<T: AsRef<[u8]>>(
file_path: &Path,
data: T,
mode: u32,