1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

chore: fix flaky test_include_dir_recursive (#19291)

Maybe fixes this on main.
This commit is contained in:
David Sherret 2023-05-28 00:03:49 -04:00 committed by GitHub
parent a96844118c
commit d43e75cbb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 17 deletions

View file

@ -536,7 +536,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
fn build_vfs(&self) -> Result<VfsBuilder, AnyError> {
if let Some(node_modules_path) = self.npm_resolver.node_modules_path() {
let mut builder = VfsBuilder::new(node_modules_path.clone());
let mut builder = VfsBuilder::new(node_modules_path.clone())?;
builder.add_dir_recursive(&node_modules_path)?;
Ok(builder)
} else {
@ -544,7 +544,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
// but also don't make this dependent on the registry url
let registry_url = self.npm_api.base_url();
let root_path = self.npm_cache.registry_folder(registry_url);
let mut builder = VfsBuilder::new(root_path);
let mut builder = VfsBuilder::new(root_path)?;
for package in self
.npm_resolution
.all_system_packages(&self.npm_system_info)

View file

@ -27,6 +27,7 @@ use serde::Serialize;
use thiserror::Error;
use crate::util;
use crate::util::fs::canonicalize_path;
#[derive(Error, Debug)]
#[error(
@ -46,9 +47,10 @@ pub struct VfsBuilder {
}
impl VfsBuilder {
pub fn new(root_path: PathBuf) -> Self {
pub fn new(root_path: PathBuf) -> Result<Self, AnyError> {
let root_path = canonicalize_path(&root_path)?;
log::debug!("Building vfs with root '{}'", root_path.display());
Self {
Ok(Self {
root_dir: VirtualDirectory {
name: root_path
.file_stem()
@ -61,7 +63,7 @@ impl VfsBuilder {
files: Vec::new(),
current_offset: 0,
file_offsets: Default::default(),
}
})
}
pub fn set_root_dir_name(&mut self, name: String) {
@ -69,6 +71,14 @@ impl VfsBuilder {
}
pub fn add_dir_recursive(&mut self, path: &Path) -> Result<(), AnyError> {
let path = canonicalize_path(path)?;
self.add_dir_recursive_internal(&path)
}
fn add_dir_recursive_internal(
&mut self,
path: &Path,
) -> Result<(), AnyError> {
self.add_dir(path)?;
let read_dir = std::fs::read_dir(path)
.with_context(|| format!("Reading {}", path.display()))?;
@ -79,7 +89,7 @@ impl VfsBuilder {
let path = entry.path();
if file_type.is_dir() {
self.add_dir_recursive(&path)?;
self.add_dir_recursive_internal(&path)?;
} else if file_type.is_file() {
let file_bytes = std::fs::read(&path)
.with_context(|| format!("Reading {}", path.display()))?;
@ -115,7 +125,7 @@ impl VfsBuilder {
Ok(())
}
pub fn add_dir(
fn add_dir(
&mut self,
path: &Path,
) -> Result<&mut VirtualDirectory, StripRootError> {
@ -152,11 +162,7 @@ impl VfsBuilder {
Ok(current_dir)
}
pub fn add_file(
&mut self,
path: &Path,
data: Vec<u8>,
) -> Result<(), AnyError> {
fn add_file(&mut self, path: &Path, data: Vec<u8>) -> Result<(), AnyError> {
log::debug!("Adding file '{}'", path.display());
let checksum = util::checksum::gen(&[&data]);
let offset = if let Some(offset) = self.file_offsets.get(&checksum) {
@ -193,7 +199,7 @@ impl VfsBuilder {
Ok(())
}
pub fn add_symlink(
fn add_symlink(
&mut self,
path: &Path,
target: &Path,
@ -833,6 +839,7 @@ mod test {
use super::*;
#[track_caller]
fn read_file(vfs: &FileBackedVfs, path: &Path) -> String {
let file = vfs.file_entry(path).unwrap();
String::from_utf8(vfs.read_file_all(file).unwrap()).unwrap()
@ -842,7 +849,8 @@ mod test {
fn builds_and_uses_virtual_fs() {
let temp_dir = TempDir::new();
let src_path = temp_dir.path().join("src");
let mut builder = VfsBuilder::new(src_path.clone());
temp_dir.create_dir_all(&src_path);
let mut builder = VfsBuilder::new(src_path.clone()).unwrap();
builder
.add_file(&src_path.join("a.txt"), "data".into())
.unwrap();
@ -923,7 +931,7 @@ mod test {
// build and create the virtual fs
let src_path = temp_dir.path().join("src");
let mut builder = VfsBuilder::new(src_path.clone());
let mut builder = VfsBuilder::new(src_path.clone()).unwrap();
builder.add_dir_recursive(&src_path).unwrap();
let (dest_path, virtual_fs) = into_virtual_fs(builder, &temp_dir);
@ -987,7 +995,8 @@ mod test {
fn circular_symlink() {
let temp_dir = TempDir::new();
let src_path = temp_dir.path().join("src");
let mut builder = VfsBuilder::new(src_path.clone());
temp_dir.create_dir_all(&src_path);
let mut builder = VfsBuilder::new(src_path.clone()).unwrap();
builder
.add_symlink(&src_path.join("a.txt"), &src_path.join("b.txt"))
.unwrap();
@ -1020,7 +1029,7 @@ mod test {
async fn test_open_file() {
let temp_dir = TempDir::new();
let temp_path = temp_dir.path();
let mut builder = VfsBuilder::new(temp_path.to_path_buf());
let mut builder = VfsBuilder::new(temp_path.to_path_buf()).unwrap();
builder
.add_file(
&temp_path.join("a.txt"),