Skip to content

Commit

Permalink
fix: Fix snapshots logic for old snapshots
Browse files Browse the repository at this point in the history
fix: Fix snapshots logic for old snapshots
  • Loading branch information
andreespirela committed Mar 21, 2024
1 parent bfc647a commit 5420f03
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions crates/base/src/rt_worker/worker_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ impl WorkerPool {
}
}

#[allow(clippy::question_mark)]
fn maybe_active_worker(&mut self, service_path: &String, force_create: bool) -> Option<Uuid> {
if force_create {
return None;
Expand Down
1 change: 1 addition & 0 deletions crates/cpu_timer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub fn get_thread_time() -> Result<i64, Error> {

#[cfg_attr(target_os = "linux", linux::ctor)]
#[cfg(target_os = "linux")]
#[allow(static_mut_refs)]
fn register_sigalrm() {
use std::collections::HashMap;

Expand Down
1 change: 1 addition & 0 deletions crates/npm/managed/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ pub fn with_folder_sync_lock(
output_folder: &Path,
action: impl FnOnce() -> Result<(), AnyError>,
) -> Result<(), AnyError> {
#[allow(clippy::suspicious_open_options)]
fn inner(
output_folder: &Path,
action: impl FnOnce() -> Result<(), AnyError>,
Expand Down
2 changes: 2 additions & 0 deletions crates/sb_core/util/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,11 @@ impl Drop for LaxSingleProcessFsFlagInner {
/// This should only be used in places where it's ideal for multiple
/// processes to not update something on the file system at the same time,
/// but it's not that big of a deal.
#[allow(dead_code)]
pub struct LaxSingleProcessFsFlag(Option<LaxSingleProcessFsFlagInner>);

impl LaxSingleProcessFsFlag {
#[allow(clippy::suspicious_open_options)]
pub async fn lock(file_path: PathBuf, _long_wait_message: &str) -> Self {
debug!("Acquiring file lock at {}", file_path.display());
use fs3::FileExt;
Expand Down
11 changes: 9 additions & 2 deletions crates/sb_fs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ pub async fn extract_static_files_from_eszip(eszip: &EszipV2) -> EszipStaticFile
files
}

pub fn load_npm_vfs(root_dir_path: PathBuf, vfs_data: &[u8]) -> Result<FileBackedVfs, AnyError> {
let dir: Option<VirtualDirectory> = serde_json::from_slice(vfs_data)?;
pub fn load_npm_vfs(
root_dir_path: PathBuf,
vfs_data: Option<&[u8]>,
) -> Result<FileBackedVfs, AnyError> {
let dir: Option<VirtualDirectory> = if let Some(vfs_data) = vfs_data {
serde_json::from_slice(vfs_data)?
} else {
None
};

let fs_root: VfsRoot = if let Some(mut dir) = dir {
// align the name of the directory with the root dir
Expand Down
33 changes: 23 additions & 10 deletions crates/sb_module_loader/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,29 @@ pub async fn create_module_loader_for_eszip(
let vfs_root_dir_path = npm_cache_dir.registry_folder(&npm_registry_url);

let (fs, vfs) = {
let vfs_data: Vec<u8> = eszip
.get_module(VFS_ESZIP_KEY)
.unwrap()
.take_source()
.await
.unwrap()
.to_vec();

let vfs = load_npm_vfs(vfs_root_dir_path.clone(), &vfs_data)
.context("Failed to load npm vfs.")?;
let key = String::from(VFS_ESZIP_KEY);
let vfs_data: Option<Vec<u8>> = if eszip.specifiers().contains(&key) {
Some(
eszip
.get_module(VFS_ESZIP_KEY)
.unwrap()
.take_source()
.await
.unwrap()
.to_vec(),
)
} else {
None
};

let vfs_data: Option<&[u8]> = if let Some(data) = &vfs_data {
Some(data)
} else {
None
};

let vfs =
load_npm_vfs(vfs_root_dir_path.clone(), vfs_data).context("Failed to load npm vfs.")?;

let fs = DenoCompileFileSystem::new(vfs);
let fs_backed_vfs = fs.file_backed_vfs().clone();
Expand Down

0 comments on commit 5420f03

Please sign in to comment.