|
|
#![allow(clippy::needless_return)] |
|
|
#![feature(trivial_bounds)] |
|
|
#![feature(min_specialization)] |
|
|
#![feature(iter_advance_by)] |
|
|
#![feature(io_error_more)] |
|
|
#![feature(round_char_boundary)] |
|
|
#![feature(arbitrary_self_types)] |
|
|
#![feature(arbitrary_self_types_pointers)] |
|
|
#![allow(clippy::mutable_key_type)] |
|
|
|
|
|
pub mod attach; |
|
|
pub mod embed; |
|
|
pub mod glob; |
|
|
mod globset; |
|
|
pub mod invalidation; |
|
|
mod invalidator_map; |
|
|
pub mod json; |
|
|
mod mutex_map; |
|
|
mod read_glob; |
|
|
mod retry; |
|
|
pub mod rope; |
|
|
pub mod source_context; |
|
|
pub mod util; |
|
|
pub(crate) mod virtual_fs; |
|
|
mod watcher; |
|
|
use std::{ |
|
|
borrow::Cow, |
|
|
cmp::{Ordering, min}, |
|
|
fmt::{self, Debug, Display, Formatter}, |
|
|
fs::FileType, |
|
|
future::Future, |
|
|
io::{self, BufRead, BufReader, ErrorKind, Read}, |
|
|
mem::take, |
|
|
path::{MAIN_SEPARATOR, Path, PathBuf}, |
|
|
sync::{Arc, LazyLock}, |
|
|
time::Duration, |
|
|
}; |
|
|
|
|
|
use anyhow::{Context, Result, anyhow, bail}; |
|
|
use auto_hash_map::{AutoMap, AutoSet}; |
|
|
use bitflags::bitflags; |
|
|
use dunce::simplified; |
|
|
use glob::Glob; |
|
|
use indexmap::IndexSet; |
|
|
use invalidator_map::InvalidatorMap; |
|
|
use jsonc_parser::{ParseOptions, parse_to_serde_value}; |
|
|
use mime::Mime; |
|
|
use rayon::iter::{IntoParallelIterator, ParallelIterator}; |
|
|
pub use read_glob::ReadGlobResult; |
|
|
use read_glob::{read_glob, track_glob}; |
|
|
use rustc_hash::FxHashSet; |
|
|
use serde::{Deserialize, Serialize}; |
|
|
use serde_json::Value; |
|
|
use tokio::sync::{RwLock, RwLockReadGuard}; |
|
|
use tracing::Instrument; |
|
|
use turbo_rcstr::{RcStr, rcstr}; |
|
|
use turbo_tasks::{ |
|
|
ApplyEffectsContext, Completion, InvalidationReason, Invalidator, NonLocalValue, ReadRef, |
|
|
ResolvedVc, TaskInput, ValueToString, Vc, debug::ValueDebugFormat, effect, |
|
|
mark_session_dependent, mark_stateful, trace::TraceRawVcs, |
|
|
}; |
|
|
use turbo_tasks_hash::{DeterministicHash, DeterministicHasher, hash_xxh3_hash64}; |
|
|
use util::{extract_disk_access, join_path, normalize_path, sys_to_unix, unix_to_sys}; |
|
|
pub use virtual_fs::VirtualFileSystem; |
|
|
use watcher::DiskWatcher; |
|
|
|
|
|
use self::{invalidation::Write, json::UnparsableJson, mutex_map::MutexMap}; |
|
|
use crate::{ |
|
|
attach::AttachedFileSystem, |
|
|
invalidator_map::WriteContent, |
|
|
retry::retry_blocking, |
|
|
rope::{Rope, RopeReader}, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub const MAX_SAFE_FILE_NAME_LENGTH: usize = 200; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn validate_path_length(path: &Path) -> Result<Cow<'_, Path>> { |
|
|
|
|
|
|
|
|
#[cfg(target_family = "windows")] |
|
|
fn validate_path_length_inner(path: &Path) -> Result<Cow<'_, Path>> { |
|
|
const MAX_PATH_LENGTH_WINDOWS: usize = 260; |
|
|
const UNC_PREFIX: &str = "\\\\?\\"; |
|
|
|
|
|
if path.starts_with(UNC_PREFIX) { |
|
|
return Ok(path.into()); |
|
|
} |
|
|
|
|
|
if path.as_os_str().len() > MAX_PATH_LENGTH_WINDOWS { |
|
|
let new_path = std::fs::canonicalize(path) |
|
|
.map_err(|_| anyhow!("file is too long, and could not be normalized"))?; |
|
|
return Ok(new_path.into()); |
|
|
} |
|
|
|
|
|
Ok(path.into()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(target_family = "windows"))] |
|
|
fn validate_path_length_inner(path: &Path) -> Result<Cow<'_, Path>> { |
|
|
const MAX_FILE_NAME_LENGTH_UNIX: usize = 255; |
|
|
|
|
|
|
|
|
|
|
|
const MAX_PATH_LENGTH: usize = 1024 - 8; |
|
|
|
|
|
|
|
|
if path |
|
|
.file_name() |
|
|
.map(|n| n.as_encoded_bytes().len()) |
|
|
.unwrap_or(0) |
|
|
> MAX_FILE_NAME_LENGTH_UNIX |
|
|
{ |
|
|
anyhow::bail!( |
|
|
"file name is too long (exceeds {} bytes)", |
|
|
MAX_FILE_NAME_LENGTH_UNIX |
|
|
); |
|
|
} |
|
|
|
|
|
if path.as_os_str().len() > MAX_PATH_LENGTH { |
|
|
anyhow::bail!("path is too long (exceeds {} bytes)", MAX_PATH_LENGTH); |
|
|
} |
|
|
|
|
|
Ok(path.into()) |
|
|
} |
|
|
|
|
|
validate_path_length_inner(path).with_context(|| { |
|
|
format!( |
|
|
"path length for file {} exceeds max length of filesystem", |
|
|
path.to_string_lossy() |
|
|
) |
|
|
}) |
|
|
} |
|
|
|
|
|
trait ConcurrencyLimitedExt { |
|
|
type Output; |
|
|
async fn concurrency_limited(self, semaphore: &tokio::sync::Semaphore) -> Self::Output; |
|
|
} |
|
|
|
|
|
impl<F, R> ConcurrencyLimitedExt for F |
|
|
where |
|
|
F: Future<Output = R>, |
|
|
{ |
|
|
type Output = R; |
|
|
async fn concurrency_limited(self, semaphore: &tokio::sync::Semaphore) -> Self::Output { |
|
|
let _permit = semaphore.acquire().await; |
|
|
self.await |
|
|
} |
|
|
} |
|
|
|
|
|
fn create_semaphore() -> tokio::sync::Semaphore { |
|
|
tokio::sync::Semaphore::new(256) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_trait] |
|
|
pub trait FileSystem: ValueToString { |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn root(self: ResolvedVc<Self>) -> Vc<FileSystemPath> { |
|
|
FileSystemPath::new_normalized(self, RcStr::default()).cell() |
|
|
} |
|
|
#[turbo_tasks::function] |
|
|
fn read(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<FileContent>; |
|
|
#[turbo_tasks::function] |
|
|
fn read_link(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<LinkContent>; |
|
|
#[turbo_tasks::function] |
|
|
fn raw_read_dir(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<RawDirectoryContent>; |
|
|
#[turbo_tasks::function] |
|
|
fn write(self: Vc<Self>, fs_path: FileSystemPath, content: Vc<FileContent>) -> Vc<()>; |
|
|
#[turbo_tasks::function] |
|
|
fn write_link(self: Vc<Self>, fs_path: FileSystemPath, target: Vc<LinkContent>) -> Vc<()>; |
|
|
#[turbo_tasks::function] |
|
|
fn metadata(self: Vc<Self>, fs_path: FileSystemPath) -> Vc<FileMeta>; |
|
|
} |
|
|
|
|
|
#[derive(Default)] |
|
|
struct DiskFileSystemApplyContext { |
|
|
|
|
|
created_directories: FxHashSet<PathBuf>, |
|
|
} |
|
|
|
|
|
#[derive(Serialize, Deserialize, TraceRawVcs, ValueDebugFormat, NonLocalValue)] |
|
|
struct DiskFileSystemInner { |
|
|
pub name: RcStr, |
|
|
pub root: RcStr, |
|
|
#[turbo_tasks(debug_ignore, trace_ignore)] |
|
|
#[serde(skip)] |
|
|
mutex_map: MutexMap<PathBuf>, |
|
|
#[turbo_tasks(debug_ignore, trace_ignore)] |
|
|
#[serde(skip)] |
|
|
invalidator_map: InvalidatorMap, |
|
|
#[turbo_tasks(debug_ignore, trace_ignore)] |
|
|
#[serde(skip)] |
|
|
dir_invalidator_map: InvalidatorMap, |
|
|
|
|
|
|
|
|
#[turbo_tasks(debug_ignore, trace_ignore)] |
|
|
#[serde(skip)] |
|
|
invalidation_lock: RwLock<()>, |
|
|
|
|
|
#[turbo_tasks(debug_ignore, trace_ignore)] |
|
|
#[serde(skip, default = "create_semaphore")] |
|
|
semaphore: tokio::sync::Semaphore, |
|
|
|
|
|
#[turbo_tasks(debug_ignore, trace_ignore)] |
|
|
watcher: DiskWatcher, |
|
|
} |
|
|
|
|
|
impl DiskFileSystemInner { |
|
|
|
|
|
fn root_path(&self) -> &Path { |
|
|
simplified(Path::new(&*self.root)) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn register_read_invalidator(&self, path: &Path) -> Result<()> { |
|
|
let invalidator = turbo_tasks::get_invalidator(); |
|
|
self.invalidator_map |
|
|
.insert(path_to_key(path), invalidator, None); |
|
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))] |
|
|
if let Some(dir) = path.parent() { |
|
|
self.watcher.ensure_watching(dir, self.root_path())?; |
|
|
} |
|
|
Ok(()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn register_write_invalidator( |
|
|
&self, |
|
|
path: &Path, |
|
|
invalidator: Invalidator, |
|
|
write_content: WriteContent, |
|
|
) -> Result<Vec<(Invalidator, Option<WriteContent>)>> { |
|
|
let mut invalidator_map = self.invalidator_map.lock().unwrap(); |
|
|
let invalidators = invalidator_map.entry(path_to_key(path)).or_default(); |
|
|
let old_invalidators = invalidators |
|
|
.extract_if(|i, old_write_content| { |
|
|
i == &invalidator |
|
|
|| old_write_content |
|
|
.as_ref() |
|
|
.is_none_or(|old| old != &write_content) |
|
|
}) |
|
|
.filter(|(i, _)| i != &invalidator) |
|
|
.collect::<Vec<_>>(); |
|
|
invalidators.insert(invalidator, Some(write_content)); |
|
|
drop(invalidator_map); |
|
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))] |
|
|
if let Some(dir) = path.parent() { |
|
|
self.watcher.ensure_watching(dir, self.root_path())?; |
|
|
} |
|
|
Ok(old_invalidators) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn register_dir_invalidator(&self, path: &Path) -> Result<()> { |
|
|
let invalidator = turbo_tasks::get_invalidator(); |
|
|
self.dir_invalidator_map |
|
|
.insert(path_to_key(path), invalidator, None); |
|
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))] |
|
|
self.watcher.ensure_watching(path, self.root_path())?; |
|
|
Ok(()) |
|
|
} |
|
|
|
|
|
async fn lock_path(&self, full_path: &Path) -> PathLockGuard<'_> { |
|
|
let lock1 = self.invalidation_lock.read().await; |
|
|
let lock2 = self.mutex_map.lock(full_path.to_path_buf()).await; |
|
|
PathLockGuard(lock1, lock2) |
|
|
} |
|
|
|
|
|
fn invalidate(&self) { |
|
|
let _span = tracing::info_span!("invalidate filesystem", name = &*self.root).entered(); |
|
|
let span = tracing::Span::current(); |
|
|
let handle = tokio::runtime::Handle::current(); |
|
|
let invalidator_map = take(&mut *self.invalidator_map.lock().unwrap()); |
|
|
let dir_invalidator_map = take(&mut *self.dir_invalidator_map.lock().unwrap()); |
|
|
let iter = invalidator_map |
|
|
.into_par_iter() |
|
|
.chain(dir_invalidator_map.into_par_iter()) |
|
|
.flat_map(|(_, invalidators)| invalidators.into_par_iter()); |
|
|
iter.for_each(|(i, _)| { |
|
|
let _span = span.clone().entered(); |
|
|
let _guard = handle.enter(); |
|
|
i.invalidate() |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn invalidate_with_reason<R: InvalidationReason + Clone>( |
|
|
&self, |
|
|
reason: impl Fn(String) -> R + Sync, |
|
|
) { |
|
|
let _span = tracing::info_span!("invalidate filesystem", name = &*self.root).entered(); |
|
|
let span = tracing::Span::current(); |
|
|
let handle = tokio::runtime::Handle::current(); |
|
|
let invalidator_map = take(&mut *self.invalidator_map.lock().unwrap()); |
|
|
let dir_invalidator_map = take(&mut *self.dir_invalidator_map.lock().unwrap()); |
|
|
let iter = invalidator_map |
|
|
.into_par_iter() |
|
|
.chain(dir_invalidator_map.into_par_iter()) |
|
|
.flat_map(|(path, invalidators)| { |
|
|
let _span = span.clone().entered(); |
|
|
let reason_for_path = reason(path); |
|
|
invalidators |
|
|
.into_par_iter() |
|
|
.map(move |i| (reason_for_path.clone(), i)) |
|
|
}); |
|
|
iter.for_each(|(reason, (invalidator, _))| { |
|
|
let _span = span.clone().entered(); |
|
|
let _guard = handle.enter(); |
|
|
invalidator.invalidate_with_reason(reason) |
|
|
}); |
|
|
} |
|
|
|
|
|
fn invalidate_from_write( |
|
|
&self, |
|
|
full_path: &Path, |
|
|
invalidators: Vec<(Invalidator, Option<WriteContent>)>, |
|
|
) { |
|
|
if !invalidators.is_empty() { |
|
|
if let Some(path) = format_absolute_fs_path(full_path, &self.name, self.root_path()) { |
|
|
if invalidators.len() == 1 { |
|
|
let (invalidator, _) = invalidators.into_iter().next().unwrap(); |
|
|
invalidator.invalidate_with_reason(Write { path }); |
|
|
} else { |
|
|
invalidators.into_iter().for_each(|(invalidator, _)| { |
|
|
invalidator.invalidate_with_reason(Write { path: path.clone() }); |
|
|
}); |
|
|
} |
|
|
} else { |
|
|
invalidators.into_iter().for_each(|(invalidator, _)| { |
|
|
invalidator.invalidate(); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[tracing::instrument(level = "info", name = "start filesystem watching", skip_all, fields(path = %self.root))] |
|
|
async fn start_watching_internal( |
|
|
self: &Arc<Self>, |
|
|
report_invalidation_reason: bool, |
|
|
poll_interval: Option<Duration>, |
|
|
) -> Result<()> { |
|
|
let root_path = self.root_path().to_path_buf(); |
|
|
|
|
|
|
|
|
retry_blocking(root_path.clone(), move |path| { |
|
|
let _tracing = |
|
|
tracing::info_span!("create root directory", name = display(path.display())) |
|
|
.entered(); |
|
|
|
|
|
std::fs::create_dir_all(path) |
|
|
}) |
|
|
.concurrency_limited(&self.semaphore) |
|
|
.await?; |
|
|
|
|
|
self.watcher |
|
|
.start_watching(self.clone(), report_invalidation_reason, poll_interval)?; |
|
|
|
|
|
Ok(()) |
|
|
} |
|
|
|
|
|
async fn create_directory(self: &Arc<Self>, directory: &Path) -> Result<()> { |
|
|
let already_created = ApplyEffectsContext::with_or_insert_with( |
|
|
DiskFileSystemApplyContext::default, |
|
|
|fs_context| fs_context.created_directories.contains(directory), |
|
|
); |
|
|
if !already_created { |
|
|
let func = |p: &Path| std::fs::create_dir_all(p); |
|
|
retry_blocking(directory.to_path_buf(), func) |
|
|
.concurrency_limited(&self.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"create directory", |
|
|
name = display(directory.display()) |
|
|
)) |
|
|
.await?; |
|
|
ApplyEffectsContext::with(|fs_context: &mut DiskFileSystemApplyContext| { |
|
|
fs_context |
|
|
.created_directories |
|
|
.insert(directory.to_path_buf()) |
|
|
}); |
|
|
} |
|
|
Ok(()) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(cell = "new", eq = "manual")] |
|
|
pub struct DiskFileSystem { |
|
|
inner: Arc<DiskFileSystemInner>, |
|
|
} |
|
|
|
|
|
impl DiskFileSystem { |
|
|
pub fn name(&self) -> &RcStr { |
|
|
&self.inner.name |
|
|
} |
|
|
|
|
|
pub fn root(&self) -> &RcStr { |
|
|
&self.inner.root |
|
|
} |
|
|
|
|
|
pub fn invalidate(&self) { |
|
|
self.inner.invalidate(); |
|
|
} |
|
|
|
|
|
pub fn invalidate_with_reason<R: InvalidationReason + Clone>( |
|
|
&self, |
|
|
reason: impl Fn(String) -> R + Sync, |
|
|
) { |
|
|
self.inner.invalidate_with_reason(reason); |
|
|
} |
|
|
|
|
|
pub async fn start_watching(&self, poll_interval: Option<Duration>) -> Result<()> { |
|
|
self.inner |
|
|
.start_watching_internal(false, poll_interval) |
|
|
.await |
|
|
} |
|
|
|
|
|
pub async fn start_watching_with_invalidation_reason( |
|
|
&self, |
|
|
poll_interval: Option<Duration>, |
|
|
) -> Result<()> { |
|
|
self.inner |
|
|
.start_watching_internal(true, poll_interval) |
|
|
.await |
|
|
} |
|
|
|
|
|
pub fn stop_watching(&self) { |
|
|
self.inner.watcher.stop_watching(); |
|
|
} |
|
|
|
|
|
pub async fn to_sys_path(&self, fs_path: FileSystemPath) -> Result<PathBuf> { |
|
|
|
|
|
let path = self.inner.root_path(); |
|
|
Ok(if fs_path.path.is_empty() { |
|
|
path.to_path_buf() |
|
|
} else { |
|
|
path.join(&*unix_to_sys(&fs_path.path)) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
#[allow(dead_code, reason = "we need to hold onto the locks")] |
|
|
struct PathLockGuard<'a>( |
|
|
#[allow(dead_code)] RwLockReadGuard<'a, ()>, |
|
|
#[allow(dead_code)] mutex_map::MutexMapGuard<'a, PathBuf>, |
|
|
); |
|
|
|
|
|
fn format_absolute_fs_path(path: &Path, name: &str, root_path: &Path) -> Option<String> { |
|
|
if let Ok(rel_path) = path.strip_prefix(root_path) { |
|
|
let path = if MAIN_SEPARATOR != '/' { |
|
|
let rel_path = rel_path.to_string_lossy().replace(MAIN_SEPARATOR, "/"); |
|
|
format!("[{name}]/{rel_path}") |
|
|
} else { |
|
|
format!("[{name}]/{}", rel_path.display()) |
|
|
}; |
|
|
Some(path) |
|
|
} else { |
|
|
None |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn path_to_key(path: impl AsRef<Path>) -> String { |
|
|
path.as_ref().to_string_lossy().to_string() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl DiskFileSystem { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub fn new(name: RcStr, root: RcStr, ignored_subpaths: Vec<RcStr>) -> Result<Vc<Self>> { |
|
|
mark_stateful(); |
|
|
|
|
|
let instance = DiskFileSystem { |
|
|
inner: Arc::new(DiskFileSystemInner { |
|
|
name, |
|
|
root, |
|
|
mutex_map: Default::default(), |
|
|
invalidation_lock: Default::default(), |
|
|
invalidator_map: InvalidatorMap::new(), |
|
|
dir_invalidator_map: InvalidatorMap::new(), |
|
|
semaphore: create_semaphore(), |
|
|
watcher: DiskWatcher::new( |
|
|
ignored_subpaths.into_iter().map(PathBuf::from).collect(), |
|
|
), |
|
|
}), |
|
|
}; |
|
|
|
|
|
Ok(Self::cell(instance)) |
|
|
} |
|
|
} |
|
|
|
|
|
impl Debug for DiskFileSystem { |
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
|
|
write!(f, "name: {}, root: {}", self.inner.name, self.inner.root) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl FileSystem for DiskFileSystem { |
|
|
#[turbo_tasks::function(fs)] |
|
|
async fn read(&self, fs_path: FileSystemPath) -> Result<Vc<FileContent>> { |
|
|
mark_session_dependent(); |
|
|
let full_path = self.to_sys_path(fs_path).await?; |
|
|
self.inner.register_read_invalidator(&full_path)?; |
|
|
|
|
|
let _lock = self.inner.lock_path(&full_path).await; |
|
|
let content = match retry_blocking(full_path.clone(), |path: &Path| File::from_path(path)) |
|
|
.concurrency_limited(&self.inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"read file", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await |
|
|
{ |
|
|
Ok(file) => FileContent::new(file), |
|
|
Err(e) if e.kind() == ErrorKind::NotFound || e.kind() == ErrorKind::InvalidFilename => { |
|
|
FileContent::NotFound |
|
|
} |
|
|
Err(e) => { |
|
|
bail!(anyhow!(e).context(format!("reading file {}", full_path.display()))) |
|
|
} |
|
|
}; |
|
|
Ok(content.cell()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function(fs)] |
|
|
async fn raw_read_dir(&self, fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> { |
|
|
mark_session_dependent(); |
|
|
let full_path = self.to_sys_path(fs_path).await?; |
|
|
self.inner.register_dir_invalidator(&full_path)?; |
|
|
|
|
|
|
|
|
|
|
|
let read_dir = match retry_blocking(full_path.clone(), |path| { |
|
|
let _span = |
|
|
tracing::info_span!("read directory", name = display(path.display())).entered(); |
|
|
std::fs::read_dir(path) |
|
|
}) |
|
|
.concurrency_limited(&self.inner.semaphore) |
|
|
.await |
|
|
{ |
|
|
Ok(dir) => dir, |
|
|
Err(e) |
|
|
if e.kind() == ErrorKind::NotFound |
|
|
|| e.kind() == ErrorKind::NotADirectory |
|
|
|| e.kind() == ErrorKind::InvalidFilename => |
|
|
{ |
|
|
return Ok(RawDirectoryContent::not_found()); |
|
|
} |
|
|
Err(e) => { |
|
|
bail!(anyhow!(e).context(format!("reading dir {}", full_path.display()))) |
|
|
} |
|
|
}; |
|
|
|
|
|
let entries = read_dir |
|
|
.filter_map(|r| { |
|
|
let e = match r { |
|
|
Ok(e) => e, |
|
|
Err(err) => return Some(Err(err.into())), |
|
|
}; |
|
|
|
|
|
|
|
|
let file_name = e.file_name().to_str()?.into(); |
|
|
|
|
|
let entry = match e.file_type() { |
|
|
Ok(t) if t.is_file() => RawDirectoryEntry::File, |
|
|
Ok(t) if t.is_dir() => RawDirectoryEntry::Directory, |
|
|
Ok(t) if t.is_symlink() => RawDirectoryEntry::Symlink, |
|
|
Ok(_) => RawDirectoryEntry::Other, |
|
|
Err(err) => return Some(Err(err.into())), |
|
|
}; |
|
|
|
|
|
Some(anyhow::Ok((file_name, entry))) |
|
|
}) |
|
|
.collect::<Result<_>>() |
|
|
.with_context(|| format!("reading directory item in {}", full_path.display()))?; |
|
|
|
|
|
Ok(RawDirectoryContent::new(entries)) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function(fs)] |
|
|
async fn read_link(&self, fs_path: FileSystemPath) -> Result<Vc<LinkContent>> { |
|
|
mark_session_dependent(); |
|
|
let full_path = self.to_sys_path(fs_path.clone()).await?; |
|
|
self.inner.register_read_invalidator(&full_path)?; |
|
|
|
|
|
let _lock = self.inner.lock_path(&full_path).await; |
|
|
let link_path = |
|
|
match retry_blocking(full_path.clone(), |path: &Path| std::fs::read_link(path)) |
|
|
.concurrency_limited(&self.inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"read symlink", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await |
|
|
{ |
|
|
Ok(res) => res, |
|
|
Err(_) => return Ok(LinkContent::NotFound.cell()), |
|
|
}; |
|
|
let is_link_absolute = link_path.is_absolute(); |
|
|
|
|
|
let mut file = link_path.clone(); |
|
|
if !is_link_absolute { |
|
|
if let Some(normalized_linked_path) = full_path.parent().and_then(|p| { |
|
|
normalize_path(&sys_to_unix(p.join(&file).to_string_lossy().as_ref())) |
|
|
}) { |
|
|
#[cfg(target_family = "windows")] |
|
|
{ |
|
|
file = PathBuf::from(normalized_linked_path); |
|
|
} |
|
|
|
|
|
|
|
|
#[cfg(not(target_family = "windows"))] |
|
|
{ |
|
|
file = PathBuf::from(format!("/{normalized_linked_path}")); |
|
|
} |
|
|
} else { |
|
|
return Ok(LinkContent::Invalid.cell()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let result = simplified(&file).strip_prefix(simplified(Path::new(&self.inner.root))); |
|
|
|
|
|
let relative_to_root_path = match result { |
|
|
Ok(file) => PathBuf::from(sys_to_unix(&file.to_string_lossy()).as_ref()), |
|
|
Err(_) => return Ok(LinkContent::Invalid.cell()), |
|
|
}; |
|
|
|
|
|
let (target, file_type) = if is_link_absolute { |
|
|
let target_string: RcStr = relative_to_root_path.to_string_lossy().into(); |
|
|
( |
|
|
target_string.clone(), |
|
|
FileSystemPath::new_normalized(fs_path.fs().to_resolved().await?, target_string) |
|
|
.get_type() |
|
|
.await?, |
|
|
) |
|
|
} else { |
|
|
let link_path_string_cow = link_path.to_string_lossy(); |
|
|
let link_path_unix: RcStr = sys_to_unix(&link_path_string_cow).into(); |
|
|
( |
|
|
link_path_unix.clone(), |
|
|
fs_path.parent().join(&link_path_unix)?.get_type().await?, |
|
|
) |
|
|
}; |
|
|
|
|
|
Ok(LinkContent::Link { |
|
|
target, |
|
|
link_type: { |
|
|
let mut link_type = Default::default(); |
|
|
if link_path.is_absolute() { |
|
|
link_type |= LinkType::ABSOLUTE; |
|
|
} |
|
|
if matches!(&*file_type, FileSystemEntryType::Directory) { |
|
|
link_type |= LinkType::DIRECTORY; |
|
|
} |
|
|
link_type |
|
|
}, |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function(fs)] |
|
|
async fn write(&self, fs_path: FileSystemPath, content: Vc<FileContent>) -> Result<()> { |
|
|
mark_session_dependent(); |
|
|
let full_path = self.to_sys_path(fs_path).await?; |
|
|
let content = content.await?; |
|
|
let inner = self.inner.clone(); |
|
|
let invalidator = turbo_tasks::get_invalidator(); |
|
|
|
|
|
effect(async move { |
|
|
let full_path = validate_path_length(&full_path)?; |
|
|
|
|
|
let _lock = inner.lock_path(&full_path).await; |
|
|
|
|
|
|
|
|
let old_invalidators = inner.register_write_invalidator( |
|
|
&full_path, |
|
|
invalidator, |
|
|
WriteContent::File(content.clone()), |
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let compare = content |
|
|
.streaming_compare(&full_path) |
|
|
.concurrency_limited(&inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"read file before write", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await?; |
|
|
if compare == FileComparison::Equal { |
|
|
if !old_invalidators.is_empty() { |
|
|
let key = path_to_key(&full_path); |
|
|
for (invalidator, write_content) in old_invalidators { |
|
|
inner |
|
|
.invalidator_map |
|
|
.insert(key.clone(), invalidator, write_content); |
|
|
} |
|
|
} |
|
|
return Ok(()); |
|
|
} |
|
|
|
|
|
match &*content { |
|
|
FileContent::Content(..) => { |
|
|
let create_directory = compare == FileComparison::Create; |
|
|
if create_directory && let Some(parent) = full_path.parent() { |
|
|
inner.create_directory(parent).await.with_context(|| { |
|
|
format!( |
|
|
"failed to create directory {} for write to {}", |
|
|
parent.display(), |
|
|
full_path.display() |
|
|
) |
|
|
})?; |
|
|
} |
|
|
|
|
|
let full_path_to_write = full_path.clone(); |
|
|
let content = content.clone(); |
|
|
retry_blocking(full_path_to_write.into_owned(), move |full_path| { |
|
|
use std::io::Write; |
|
|
|
|
|
let mut f = std::fs::File::create(full_path)?; |
|
|
let FileContent::Content(file) = &*content else { |
|
|
unreachable!() |
|
|
}; |
|
|
std::io::copy(&mut file.read(), &mut f)?; |
|
|
#[cfg(target_family = "unix")] |
|
|
f.set_permissions(file.meta.permissions.into())?; |
|
|
f.flush()?; |
|
|
|
|
|
static WRITE_VERSION: LazyLock<bool> = LazyLock::new(|| { |
|
|
std::env::var_os("TURBO_ENGINE_WRITE_VERSION") |
|
|
.is_some_and(|v| v == "1" || v == "true") |
|
|
}); |
|
|
if *WRITE_VERSION { |
|
|
let mut full_path = full_path.to_owned(); |
|
|
let hash = hash_xxh3_hash64(file); |
|
|
let ext = full_path.extension(); |
|
|
let ext = if let Some(ext) = ext { |
|
|
format!("{:016x}.{}", hash, ext.to_string_lossy()) |
|
|
} else { |
|
|
format!("{hash:016x}") |
|
|
}; |
|
|
full_path.set_extension(ext); |
|
|
let mut f = std::fs::File::create(&full_path)?; |
|
|
std::io::copy(&mut file.read(), &mut f)?; |
|
|
#[cfg(target_family = "unix")] |
|
|
f.set_permissions(file.meta.permissions.into())?; |
|
|
f.flush()?; |
|
|
} |
|
|
Ok::<(), io::Error>(()) |
|
|
}) |
|
|
.concurrency_limited(&inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"write file", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await |
|
|
.with_context(|| format!("failed to write to {}", full_path.display()))?; |
|
|
} |
|
|
FileContent::NotFound => { |
|
|
retry_blocking(full_path.clone().into_owned(), |path| { |
|
|
std::fs::remove_file(path) |
|
|
}) |
|
|
.concurrency_limited(&inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"remove file", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await |
|
|
.or_else(|err| { |
|
|
if err.kind() == ErrorKind::NotFound { |
|
|
Ok(()) |
|
|
} else { |
|
|
Err(err) |
|
|
} |
|
|
}) |
|
|
.with_context(|| anyhow!("removing {} failed", full_path.display()))?; |
|
|
} |
|
|
} |
|
|
|
|
|
inner.invalidate_from_write(&full_path, old_invalidators); |
|
|
|
|
|
Ok(()) |
|
|
}); |
|
|
|
|
|
Ok(()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function(fs)] |
|
|
async fn write_link(&self, fs_path: FileSystemPath, target: Vc<LinkContent>) -> Result<()> { |
|
|
mark_session_dependent(); |
|
|
let full_path = self.to_sys_path(fs_path).await?; |
|
|
let content = target.await?; |
|
|
let inner = self.inner.clone(); |
|
|
let invalidator = turbo_tasks::get_invalidator(); |
|
|
|
|
|
effect(async move { |
|
|
let full_path = validate_path_length(&full_path)?; |
|
|
|
|
|
let _lock = inner.lock_path(&full_path).await; |
|
|
|
|
|
let old_invalidators = inner.register_write_invalidator( |
|
|
&full_path, |
|
|
invalidator, |
|
|
WriteContent::Link(content.clone()), |
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
let old_content = match retry_blocking(full_path.clone().into_owned(), |path| { |
|
|
std::fs::read_link(path) |
|
|
}) |
|
|
.concurrency_limited(&inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"read symlink before write", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await |
|
|
{ |
|
|
Ok(res) => Some((res.is_absolute(), res)), |
|
|
Err(_) => None, |
|
|
}; |
|
|
let is_equal = match (&*content, &old_content) { |
|
|
(LinkContent::Link { target, link_type }, Some((old_is_absolute, old_target))) => { |
|
|
Path::new(&**target) == old_target |
|
|
&& link_type.contains(LinkType::ABSOLUTE) == *old_is_absolute |
|
|
} |
|
|
(LinkContent::NotFound, None) => true, |
|
|
_ => false, |
|
|
}; |
|
|
if is_equal { |
|
|
if !old_invalidators.is_empty() { |
|
|
let key = path_to_key(&full_path); |
|
|
for (invalidator, write_content) in old_invalidators { |
|
|
inner |
|
|
.invalidator_map |
|
|
.insert(key.clone(), invalidator, write_content); |
|
|
} |
|
|
} |
|
|
return Ok(()); |
|
|
} |
|
|
|
|
|
match &*content { |
|
|
LinkContent::Link { target, link_type } => { |
|
|
let create_directory = old_content.is_none(); |
|
|
if create_directory && let Some(parent) = full_path.parent() { |
|
|
inner.create_directory(parent).await.with_context(|| { |
|
|
format!( |
|
|
"failed to create directory {} for write link to {}", |
|
|
parent.display(), |
|
|
full_path.display() |
|
|
) |
|
|
})?; |
|
|
} |
|
|
|
|
|
let link_type = *link_type; |
|
|
let target_path = if link_type.contains(LinkType::ABSOLUTE) { |
|
|
Path::new(&inner.root).join(unix_to_sys(target).as_ref()) |
|
|
} else { |
|
|
PathBuf::from(unix_to_sys(target).as_ref()) |
|
|
}; |
|
|
let full_path = full_path.into_owned(); |
|
|
retry_blocking(target_path, move |target_path| { |
|
|
let _span = tracing::info_span!( |
|
|
"write symlink", |
|
|
name = display(target_path.display()) |
|
|
) |
|
|
.entered(); |
|
|
|
|
|
|
|
|
#[cfg(not(target_family = "windows"))] |
|
|
{ |
|
|
std::os::unix::fs::symlink(target_path, &full_path) |
|
|
} |
|
|
#[cfg(target_family = "windows")] |
|
|
{ |
|
|
if link_type.contains(LinkType::DIRECTORY) { |
|
|
std::os::windows::fs::symlink_dir(target_path, &full_path) |
|
|
} else { |
|
|
std::os::windows::fs::symlink_file(target_path, &full_path) |
|
|
} |
|
|
} |
|
|
}) |
|
|
.await |
|
|
.with_context(|| format!("create symlink to {target}"))?; |
|
|
} |
|
|
LinkContent::Invalid => { |
|
|
anyhow::bail!("invalid symlink target: {}", full_path.display()) |
|
|
} |
|
|
LinkContent::NotFound => { |
|
|
retry_blocking(full_path.clone().into_owned(), |path| { |
|
|
std::fs::remove_file(path) |
|
|
}) |
|
|
.concurrency_limited(&inner.semaphore) |
|
|
.await |
|
|
.or_else(|err| { |
|
|
if err.kind() == ErrorKind::NotFound { |
|
|
Ok(()) |
|
|
} else { |
|
|
Err(err) |
|
|
} |
|
|
}) |
|
|
.with_context(|| anyhow!("removing {} failed", full_path.display()))?; |
|
|
} |
|
|
} |
|
|
|
|
|
Ok(()) |
|
|
}); |
|
|
Ok(()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function(fs)] |
|
|
async fn metadata(&self, fs_path: FileSystemPath) -> Result<Vc<FileMeta>> { |
|
|
mark_session_dependent(); |
|
|
let full_path = self.to_sys_path(fs_path).await?; |
|
|
self.inner.register_read_invalidator(&full_path)?; |
|
|
|
|
|
let _lock = self.inner.lock_path(&full_path).await; |
|
|
let meta = retry_blocking(full_path.clone(), |path| std::fs::metadata(path)) |
|
|
.concurrency_limited(&self.inner.semaphore) |
|
|
.instrument(tracing::info_span!( |
|
|
"read metadata", |
|
|
name = display(full_path.display()) |
|
|
)) |
|
|
.await |
|
|
.with_context(|| format!("reading metadata for {}", full_path.display()))?; |
|
|
|
|
|
Ok(FileMeta::cell(meta.into())) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ValueToString for DiskFileSystem { |
|
|
#[turbo_tasks::function] |
|
|
fn to_string(&self) -> Vc<RcStr> { |
|
|
Vc::cell(self.inner.name.clone()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn get_relative_path_to(path: &str, other_path: &str) -> String { |
|
|
fn split(s: &str) -> impl Iterator<Item = &str> { |
|
|
let empty = s.is_empty(); |
|
|
let mut iterator = s.split('/'); |
|
|
if empty { |
|
|
iterator.next(); |
|
|
} |
|
|
iterator |
|
|
} |
|
|
|
|
|
let mut self_segments = split(path).peekable(); |
|
|
let mut other_segments = split(other_path).peekable(); |
|
|
while self_segments.peek() == other_segments.peek() { |
|
|
self_segments.next(); |
|
|
if other_segments.next().is_none() { |
|
|
return ".".to_string(); |
|
|
} |
|
|
} |
|
|
let mut result = Vec::new(); |
|
|
if self_segments.peek().is_none() { |
|
|
result.push("."); |
|
|
} else { |
|
|
while self_segments.next().is_some() { |
|
|
result.push(".."); |
|
|
} |
|
|
} |
|
|
for segment in other_segments { |
|
|
result.push(segment); |
|
|
} |
|
|
result.join("/") |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
#[derive(Debug, Clone, Hash, TaskInput)] |
|
|
pub struct FileSystemPath { |
|
|
pub fs: ResolvedVc<Box<dyn FileSystem>>, |
|
|
pub path: RcStr, |
|
|
} |
|
|
|
|
|
impl FileSystemPath { |
|
|
|
|
|
pub fn value_to_string(&self) -> Vc<RcStr> { |
|
|
value_to_string(self.clone()) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn value_to_string(path: FileSystemPath) -> Result<Vc<RcStr>> { |
|
|
Ok(Vc::cell( |
|
|
format!("[{}]/{}", path.fs.to_string().await?, path.path).into(), |
|
|
)) |
|
|
} |
|
|
|
|
|
impl FileSystemPath { |
|
|
pub fn is_inside_ref(&self, other: &FileSystemPath) -> bool { |
|
|
if self.fs == other.fs && self.path.starts_with(&*other.path) { |
|
|
if other.path.is_empty() { |
|
|
true |
|
|
} else { |
|
|
self.path.as_bytes().get(other.path.len()) == Some(&b'/') |
|
|
} |
|
|
} else { |
|
|
false |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn is_inside_or_equal_ref(&self, other: &FileSystemPath) -> bool { |
|
|
if self.fs == other.fs && self.path.starts_with(&*other.path) { |
|
|
if other.path.is_empty() { |
|
|
true |
|
|
} else { |
|
|
matches!( |
|
|
self.path.as_bytes().get(other.path.len()), |
|
|
Some(&b'/') | None |
|
|
) |
|
|
} |
|
|
} else { |
|
|
false |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn is_root(&self) -> bool { |
|
|
self.path.is_empty() |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_path_to<'a>(&self, inner: &'a FileSystemPath) -> Option<&'a str> { |
|
|
if self.fs != inner.fs { |
|
|
return None; |
|
|
} |
|
|
let path = inner.path.strip_prefix(&*self.path)?; |
|
|
if self.path.is_empty() { |
|
|
Some(path) |
|
|
} else if let Some(stripped) = path.strip_prefix('/') { |
|
|
Some(stripped) |
|
|
} else { |
|
|
None |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn get_relative_path_to(&self, other: &FileSystemPath) -> Option<RcStr> { |
|
|
if self.fs != other.fs { |
|
|
return None; |
|
|
} |
|
|
|
|
|
Some(get_relative_path_to(&self.path, &other.path).into()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn file_name(&self) -> &str { |
|
|
let (_, file_name) = self.split_file_name(); |
|
|
file_name |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn has_extension(&self, extension: &str) -> bool { |
|
|
debug_assert!(!extension.contains('/') && extension.starts_with('.')); |
|
|
self.path.ends_with(extension) |
|
|
} |
|
|
|
|
|
|
|
|
pub fn extension_ref(&self) -> Option<&str> { |
|
|
let (_, extension) = self.split_extension(); |
|
|
extension |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn split_extension(&self) -> (&str, Option<&str>) { |
|
|
if let Some((path_before_extension, extension)) = self.path.rsplit_once('.') { |
|
|
if extension.contains('/') || |
|
|
|
|
|
path_before_extension.ends_with('/') || path_before_extension.is_empty() |
|
|
{ |
|
|
(self.path.as_str(), None) |
|
|
} else { |
|
|
(path_before_extension, Some(extension)) |
|
|
} |
|
|
} else { |
|
|
(self.path.as_str(), None) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn split_file_name(&self) -> (Option<&str>, &str) { |
|
|
|
|
|
if let Some((parent, file_name)) = self.path.rsplit_once('/') { |
|
|
(Some(parent), file_name) |
|
|
} else { |
|
|
(None, self.path.as_str()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn split_file_stem_extension(&self) -> (Option<&str>, &str, Option<&str>) { |
|
|
let (path_before_extension, extension) = self.split_extension(); |
|
|
|
|
|
if let Some((parent, file_stem)) = path_before_extension.rsplit_once('/') { |
|
|
(Some(parent), file_stem, extension) |
|
|
} else { |
|
|
(None, path_before_extension, extension) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(transparent)] |
|
|
pub struct FileSystemPathOption(Option<FileSystemPath>); |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl FileSystemPathOption { |
|
|
#[turbo_tasks::function] |
|
|
pub fn none() -> Vc<Self> { |
|
|
Vc::cell(None) |
|
|
} |
|
|
} |
|
|
|
|
|
impl FileSystemPath { |
|
|
|
|
|
|
|
|
|
|
|
fn new_normalized(fs: ResolvedVc<Box<dyn FileSystem>>, path: RcStr) -> Self { |
|
|
|
|
|
|
|
|
|
|
|
debug_assert!( |
|
|
MAIN_SEPARATOR != '\\' || !path.contains('\\'), |
|
|
"path {path} must not contain a Windows directory '\\', it must be normalized to Unix \ |
|
|
'/'", |
|
|
); |
|
|
debug_assert!( |
|
|
normalize_path(&path).as_deref() == Some(&*path), |
|
|
"path {path} must be normalized", |
|
|
); |
|
|
FileSystemPath { fs, path } |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn join(&self, path: &str) -> Result<Self> { |
|
|
if let Some(path) = join_path(&self.path, path) { |
|
|
Ok(Self::new_normalized(self.fs, path.into())) |
|
|
} else { |
|
|
bail!( |
|
|
"FileSystemPath(\"{}\").join(\"{}\") leaves the filesystem root", |
|
|
self.path, |
|
|
path |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn append(&self, path: &str) -> Result<Self> { |
|
|
if path.contains('/') { |
|
|
bail!( |
|
|
"FileSystemPath(\"{}\").append(\"{}\") must not append '/'", |
|
|
self.path, |
|
|
path |
|
|
) |
|
|
} |
|
|
Ok(Self::new_normalized( |
|
|
self.fs, |
|
|
format!("{}{}", self.path, path).into(), |
|
|
)) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn append_to_stem(&self, appending: &str) -> Result<Self> { |
|
|
if appending.contains('/') { |
|
|
bail!( |
|
|
"FileSystemPath(\"{}\").append_to_stem(\"{}\") must not append '/'", |
|
|
self.path, |
|
|
appending |
|
|
) |
|
|
} |
|
|
if let (path, Some(ext)) = self.split_extension() { |
|
|
return Ok(Self::new_normalized( |
|
|
self.fs, |
|
|
format!("{path}{appending}.{ext}").into(), |
|
|
)); |
|
|
} |
|
|
Ok(Self::new_normalized( |
|
|
self.fs, |
|
|
format!("{}{}", self.path, appending).into(), |
|
|
)) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::needless_borrow)] |
|
|
pub fn try_join(&self, path: &str) -> Result<Option<FileSystemPath>> { |
|
|
|
|
|
#[cfg(target_os = "windows")] |
|
|
let path = path.replace('\\', "/"); |
|
|
|
|
|
if let Some(path) = join_path(&self.path, &path) { |
|
|
Ok(Some(Self::new_normalized(self.fs, path.into()))) |
|
|
} else { |
|
|
Ok(None) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn try_join_inside(&self, path: &str) -> Result<Option<FileSystemPath>> { |
|
|
if let Some(path) = join_path(&self.path, path) |
|
|
&& path.starts_with(&*self.path) |
|
|
{ |
|
|
return Ok(Some(Self::new_normalized(self.fs, path.into()))); |
|
|
} |
|
|
Ok(None) |
|
|
} |
|
|
|
|
|
pub fn read_glob(&self, glob: Vc<Glob>) -> Vc<ReadGlobResult> { |
|
|
read_glob(self.clone(), glob) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn track_glob(&self, glob: Vc<Glob>, include_dot_files: bool) -> Vc<Completion> { |
|
|
track_glob(self.clone(), glob, include_dot_files) |
|
|
} |
|
|
|
|
|
pub fn root(&self) -> Vc<Self> { |
|
|
self.fs().root() |
|
|
} |
|
|
} |
|
|
|
|
|
impl FileSystemPath { |
|
|
pub fn fs(&self) -> Vc<Box<dyn FileSystem>> { |
|
|
*self.fs |
|
|
} |
|
|
|
|
|
pub fn extension(&self) -> &str { |
|
|
self.extension_ref().unwrap_or_default() |
|
|
} |
|
|
|
|
|
pub fn is_inside(&self, other: &FileSystemPath) -> bool { |
|
|
self.is_inside_ref(other) |
|
|
} |
|
|
|
|
|
pub fn is_inside_or_equal(&self, other: &FileSystemPath) -> bool { |
|
|
self.is_inside_or_equal_ref(other) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn with_extension(&self, extension: &str) -> FileSystemPath { |
|
|
let (path_without_extension, _) = self.split_extension(); |
|
|
Self::new_normalized( |
|
|
self.fs, |
|
|
|
|
|
|
|
|
match extension.is_empty() { |
|
|
true => path_without_extension.into(), |
|
|
false => format!("{path_without_extension}.{extension}").into(), |
|
|
}, |
|
|
) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn file_stem(&self) -> Option<&str> { |
|
|
let (_, file_stem, _) = self.split_file_stem_extension(); |
|
|
if file_stem.is_empty() { |
|
|
return None; |
|
|
} |
|
|
Some(file_stem) |
|
|
} |
|
|
} |
|
|
|
|
|
impl Display for FileSystemPath { |
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
|
|
write!(f, "{}", self.path) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn rebase( |
|
|
fs_path: FileSystemPath, |
|
|
old_base: FileSystemPath, |
|
|
new_base: FileSystemPath, |
|
|
) -> Result<Vc<FileSystemPath>> { |
|
|
let new_path; |
|
|
if old_base.path.is_empty() { |
|
|
if new_base.path.is_empty() { |
|
|
new_path = fs_path.path.clone(); |
|
|
} else { |
|
|
new_path = [new_base.path.as_str(), "/", &fs_path.path].concat().into(); |
|
|
} |
|
|
} else { |
|
|
let base_path = [&old_base.path, "/"].concat(); |
|
|
if !fs_path.path.starts_with(&base_path) { |
|
|
bail!( |
|
|
"rebasing {} from {} onto {} doesn't work because it's not part of the source path", |
|
|
fs_path.to_string(), |
|
|
old_base.to_string(), |
|
|
new_base.to_string() |
|
|
); |
|
|
} |
|
|
if new_base.path.is_empty() { |
|
|
new_path = [&fs_path.path[base_path.len()..]].concat().into(); |
|
|
} else { |
|
|
new_path = [new_base.path.as_str(), &fs_path.path[old_base.path.len()..]] |
|
|
.concat() |
|
|
.into(); |
|
|
} |
|
|
} |
|
|
Ok(new_base.fs.root().await?.join(&new_path)?.cell()) |
|
|
} |
|
|
|
|
|
|
|
|
impl FileSystemPath { |
|
|
pub fn read(&self) -> Vc<FileContent> { |
|
|
self.fs().read(self.clone()) |
|
|
} |
|
|
|
|
|
pub fn read_link(&self) -> Vc<LinkContent> { |
|
|
self.fs().read_link(self.clone()) |
|
|
} |
|
|
|
|
|
pub fn read_json(&self) -> Vc<FileJsonContent> { |
|
|
self.fs().read(self.clone()).parse_json() |
|
|
} |
|
|
|
|
|
pub fn read_json5(&self) -> Vc<FileJsonContent> { |
|
|
self.fs().read(self.clone()).parse_json5() |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn raw_read_dir(&self) -> Vc<RawDirectoryContent> { |
|
|
self.fs().raw_read_dir(self.clone()) |
|
|
} |
|
|
|
|
|
pub fn write(&self, content: Vc<FileContent>) -> Vc<()> { |
|
|
self.fs().write(self.clone(), content) |
|
|
} |
|
|
|
|
|
pub fn write_link(&self, target: Vc<LinkContent>) -> Vc<()> { |
|
|
self.fs().write_link(self.clone(), target) |
|
|
} |
|
|
|
|
|
pub fn metadata(&self) -> Vc<FileMeta> { |
|
|
self.fs().metadata(self.clone()) |
|
|
} |
|
|
|
|
|
pub fn realpath(&self) -> Vc<FileSystemPath> { |
|
|
self.realpath_with_links().path() |
|
|
} |
|
|
|
|
|
pub fn rebase( |
|
|
fs_path: FileSystemPath, |
|
|
old_base: FileSystemPath, |
|
|
new_base: FileSystemPath, |
|
|
) -> Vc<FileSystemPath> { |
|
|
rebase(fs_path, old_base, new_base) |
|
|
} |
|
|
} |
|
|
|
|
|
impl FileSystemPath { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn read_dir(&self) -> Vc<DirectoryContent> { |
|
|
read_dir(self.clone()) |
|
|
} |
|
|
|
|
|
pub fn parent(&self) -> FileSystemPath { |
|
|
let path = &self.path; |
|
|
if path.is_empty() { |
|
|
return self.clone(); |
|
|
} |
|
|
let p = match str::rfind(path, '/') { |
|
|
Some(index) => path[..index].to_string(), |
|
|
None => "".to_string(), |
|
|
}; |
|
|
FileSystemPath::new_normalized(self.fs, p.into()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_type(&self) -> Vc<FileSystemEntryType> { |
|
|
get_type(self.clone()) |
|
|
} |
|
|
|
|
|
pub fn realpath_with_links(&self) -> Vc<RealPathResult> { |
|
|
realpath_with_links(self.clone()) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ValueToString for FileSystemPath { |
|
|
#[turbo_tasks::function] |
|
|
async fn to_string(&self) -> Result<Vc<RcStr>> { |
|
|
Ok(Vc::cell( |
|
|
format!("[{}]/{}", self.fs.to_string().await?, self.path).into(), |
|
|
)) |
|
|
} |
|
|
} |
|
|
|
|
|
#[derive(Clone, Debug)] |
|
|
#[turbo_tasks::value(shared)] |
|
|
pub struct RealPathResult { |
|
|
pub path: FileSystemPath, |
|
|
pub symlinks: Vec<FileSystemPath>, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl RealPathResult { |
|
|
#[turbo_tasks::function] |
|
|
pub fn path(&self) -> Vc<FileSystemPath> { |
|
|
self.path.clone().cell() |
|
|
} |
|
|
} |
|
|
|
|
|
#[derive(Clone, Copy, Debug, DeterministicHash, PartialOrd, Ord)] |
|
|
#[turbo_tasks::value(shared)] |
|
|
pub enum Permissions { |
|
|
Readable, |
|
|
Writable, |
|
|
Executable, |
|
|
} |
|
|
|
|
|
impl Default for Permissions { |
|
|
fn default() -> Self { |
|
|
Self::Writable |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_family = "unix")] |
|
|
impl From<Permissions> for std::fs::Permissions { |
|
|
fn from(perm: Permissions) -> Self { |
|
|
use std::os::unix::fs::PermissionsExt; |
|
|
match perm { |
|
|
Permissions::Readable => std::fs::Permissions::from_mode(0o444), |
|
|
Permissions::Writable => std::fs::Permissions::from_mode(0o664), |
|
|
Permissions::Executable => std::fs::Permissions::from_mode(0o755), |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[cfg(target_family = "unix")] |
|
|
impl From<std::fs::Permissions> for Permissions { |
|
|
fn from(perm: std::fs::Permissions) -> Self { |
|
|
use std::os::unix::fs::PermissionsExt; |
|
|
if perm.readonly() { |
|
|
Permissions::Readable |
|
|
} else { |
|
|
|
|
|
if perm.mode() & 0o111 != 0 { |
|
|
Permissions::Executable |
|
|
} else { |
|
|
Permissions::Writable |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[cfg(not(target_family = "unix"))] |
|
|
impl From<std::fs::Permissions> for Permissions { |
|
|
fn from(_: std::fs::Permissions) -> Self { |
|
|
Permissions::default() |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
#[derive(Clone, Debug, DeterministicHash, PartialOrd, Ord)] |
|
|
pub enum FileContent { |
|
|
Content(File), |
|
|
NotFound, |
|
|
} |
|
|
|
|
|
impl From<File> for FileContent { |
|
|
fn from(file: File) -> Self { |
|
|
FileContent::Content(file) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<File> for Vc<FileContent> { |
|
|
fn from(file: File) -> Self { |
|
|
FileContent::Content(file).cell() |
|
|
} |
|
|
} |
|
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)] |
|
|
enum FileComparison { |
|
|
Create, |
|
|
Equal, |
|
|
NotEqual, |
|
|
} |
|
|
|
|
|
impl FileContent { |
|
|
|
|
|
|
|
|
async fn streaming_compare(&self, path: &Path) -> Result<FileComparison> { |
|
|
let old_file = extract_disk_access( |
|
|
retry_blocking(path.to_path_buf(), |path| std::fs::File::open(path)).await, |
|
|
path, |
|
|
)?; |
|
|
let Some(old_file) = old_file else { |
|
|
return Ok(match self { |
|
|
FileContent::NotFound => FileComparison::Equal, |
|
|
_ => FileComparison::Create, |
|
|
}); |
|
|
}; |
|
|
|
|
|
let FileContent::Content(new_file) = self else { |
|
|
return Ok(FileComparison::NotEqual); |
|
|
}; |
|
|
|
|
|
let old_meta = extract_disk_access( |
|
|
retry_blocking(path.to_path_buf(), { |
|
|
let file_for_metadata = old_file.try_clone()?; |
|
|
move |_| file_for_metadata.metadata() |
|
|
}) |
|
|
.await, |
|
|
path, |
|
|
)?; |
|
|
let Some(old_meta) = old_meta else { |
|
|
|
|
|
|
|
|
|
|
|
return Ok(FileComparison::Create); |
|
|
}; |
|
|
|
|
|
if new_file.meta != old_meta.into() { |
|
|
return Ok(FileComparison::NotEqual); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let mut new_contents = new_file.read(); |
|
|
let mut old_contents = BufReader::new(old_file); |
|
|
Ok(loop { |
|
|
let new_chunk = new_contents.fill_buf()?; |
|
|
let Ok(old_chunk) = old_contents.fill_buf() else { |
|
|
break FileComparison::NotEqual; |
|
|
}; |
|
|
|
|
|
let len = min(new_chunk.len(), old_chunk.len()); |
|
|
if len == 0 { |
|
|
if new_chunk.len() == old_chunk.len() { |
|
|
break FileComparison::Equal; |
|
|
} else { |
|
|
break FileComparison::NotEqual; |
|
|
} |
|
|
} |
|
|
|
|
|
if new_chunk[0..len] != old_chunk[0..len] { |
|
|
break FileComparison::NotEqual; |
|
|
} |
|
|
|
|
|
new_contents.consume(len); |
|
|
old_contents.consume(len); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
bitflags! { |
|
|
#[derive(Default, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] |
|
|
pub struct LinkType: u8 { |
|
|
const DIRECTORY = 0b00000001; |
|
|
const ABSOLUTE = 0b00000010; |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
#[derive(Debug)] |
|
|
pub enum LinkContent { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Link { target: RcStr, link_type: LinkType }, |
|
|
Invalid, |
|
|
NotFound, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
#[derive(Clone, DeterministicHash, PartialOrd, Ord)] |
|
|
pub struct File { |
|
|
#[turbo_tasks(debug_ignore)] |
|
|
content: Rope, |
|
|
meta: FileMeta, |
|
|
} |
|
|
|
|
|
impl File { |
|
|
|
|
|
fn from_path(p: &Path) -> io::Result<Self> { |
|
|
let mut file = std::fs::File::open(p)?; |
|
|
let metadata = file.metadata()?; |
|
|
|
|
|
let mut output = Vec::with_capacity(metadata.len() as usize); |
|
|
file.read_to_end(&mut output)?; |
|
|
|
|
|
Ok(File { |
|
|
meta: metadata.into(), |
|
|
content: Rope::from(output), |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
fn from_bytes(content: Vec<u8>) -> Self { |
|
|
File { |
|
|
meta: FileMeta::default(), |
|
|
content: Rope::from(content), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fn from_rope(content: Rope) -> Self { |
|
|
File { |
|
|
meta: FileMeta::default(), |
|
|
content, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn content_type(&self) -> Option<&Mime> { |
|
|
self.meta.content_type.as_ref() |
|
|
} |
|
|
|
|
|
|
|
|
pub fn with_content_type(mut self, content_type: Mime) -> Self { |
|
|
self.meta.content_type = Some(content_type); |
|
|
self |
|
|
} |
|
|
|
|
|
|
|
|
pub fn read(&self) -> RopeReader { |
|
|
self.content.read() |
|
|
} |
|
|
} |
|
|
|
|
|
impl Debug for File { |
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
|
|
f.debug_struct("File") |
|
|
.field("meta", &self.meta) |
|
|
.field("content (hash)", &hash_xxh3_hash64(&self.content)) |
|
|
.finish() |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<RcStr> for File { |
|
|
fn from(s: RcStr) -> Self { |
|
|
s.into_owned().into() |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<String> for File { |
|
|
fn from(s: String) -> Self { |
|
|
File::from_bytes(s.into_bytes()) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<ReadRef<RcStr>> for File { |
|
|
fn from(s: ReadRef<RcStr>) -> Self { |
|
|
File::from_bytes(s.as_bytes().to_vec()) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<&str> for File { |
|
|
fn from(s: &str) -> Self { |
|
|
File::from_bytes(s.as_bytes().to_vec()) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<Vec<u8>> for File { |
|
|
fn from(bytes: Vec<u8>) -> Self { |
|
|
File::from_bytes(bytes) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<&[u8]> for File { |
|
|
fn from(bytes: &[u8]) -> Self { |
|
|
File::from_bytes(bytes.to_vec()) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<ReadRef<Rope>> for File { |
|
|
fn from(rope: ReadRef<Rope>) -> Self { |
|
|
File::from_rope(ReadRef::into_owned(rope)) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<Rope> for File { |
|
|
fn from(rope: Rope) -> Self { |
|
|
File::from_rope(rope) |
|
|
} |
|
|
} |
|
|
|
|
|
impl File { |
|
|
pub fn new(meta: FileMeta, content: Vec<u8>) -> Self { |
|
|
Self { |
|
|
meta, |
|
|
content: Rope::from(content), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn meta(&self) -> &FileMeta { |
|
|
&self.meta |
|
|
} |
|
|
|
|
|
|
|
|
pub fn content(&self) -> &Rope { |
|
|
&self.content |
|
|
} |
|
|
} |
|
|
|
|
|
mod mime_option_serde { |
|
|
use std::{fmt, str::FromStr}; |
|
|
|
|
|
use mime::Mime; |
|
|
use serde::{Deserializer, Serializer, de}; |
|
|
|
|
|
pub fn serialize<S>(mime: &Option<Mime>, serializer: S) -> Result<S::Ok, S::Error> |
|
|
where |
|
|
S: Serializer, |
|
|
{ |
|
|
if let Some(mime) = mime { |
|
|
serializer.serialize_str(mime.as_ref()) |
|
|
} else { |
|
|
serializer.serialize_str("") |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Mime>, D::Error> |
|
|
where |
|
|
D: Deserializer<'de>, |
|
|
{ |
|
|
struct Visitor; |
|
|
|
|
|
impl de::Visitor<'_> for Visitor { |
|
|
type Value = Option<Mime>; |
|
|
|
|
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
|
|
formatter.write_str("a valid MIME type or empty string") |
|
|
} |
|
|
|
|
|
fn visit_str<E>(self, value: &str) -> Result<Option<Mime>, E> |
|
|
where |
|
|
E: de::Error, |
|
|
{ |
|
|
if value.is_empty() { |
|
|
Ok(None) |
|
|
} else { |
|
|
Mime::from_str(value) |
|
|
.map(Some) |
|
|
.map_err(|e| E::custom(format!("{e}"))) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
deserializer.deserialize_str(Visitor) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
#[derive(Debug, Clone, Default)] |
|
|
pub struct FileMeta { |
|
|
|
|
|
|
|
|
permissions: Permissions, |
|
|
#[serde(with = "mime_option_serde")] |
|
|
#[turbo_tasks(trace_ignore)] |
|
|
content_type: Option<Mime>, |
|
|
} |
|
|
|
|
|
impl Ord for FileMeta { |
|
|
fn cmp(&self, other: &Self) -> Ordering { |
|
|
self.permissions |
|
|
.cmp(&other.permissions) |
|
|
.then_with(|| self.content_type.as_ref().cmp(&other.content_type.as_ref())) |
|
|
} |
|
|
} |
|
|
|
|
|
impl PartialOrd for FileMeta { |
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
|
|
Some(self.cmp(other)) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<std::fs::Metadata> for FileMeta { |
|
|
fn from(meta: std::fs::Metadata) -> Self { |
|
|
let permissions = meta.permissions().into(); |
|
|
|
|
|
Self { |
|
|
permissions, |
|
|
content_type: None, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl DeterministicHash for FileMeta { |
|
|
fn deterministic_hash<H: DeterministicHasher>(&self, state: &mut H) { |
|
|
self.permissions.deterministic_hash(state); |
|
|
if let Some(content_type) = &self.content_type { |
|
|
content_type.to_string().deterministic_hash(state); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl FileContent { |
|
|
pub fn new(file: File) -> Self { |
|
|
FileContent::Content(file) |
|
|
} |
|
|
|
|
|
pub fn is_content(&self) -> bool { |
|
|
matches!(self, FileContent::Content(_)) |
|
|
} |
|
|
|
|
|
pub fn as_content(&self) -> Option<&File> { |
|
|
match self { |
|
|
FileContent::Content(file) => Some(file), |
|
|
FileContent::NotFound => None, |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn parse_json_ref(&self) -> FileJsonContent { |
|
|
match self { |
|
|
FileContent::Content(file) => { |
|
|
let content = file.content.clone().into_bytes(); |
|
|
let de = &mut serde_json::Deserializer::from_slice(&content); |
|
|
match serde_path_to_error::deserialize(de) { |
|
|
Ok(data) => FileJsonContent::Content(data), |
|
|
Err(e) => FileJsonContent::Unparsable(Box::new( |
|
|
UnparsableJson::from_serde_path_to_error(e), |
|
|
)), |
|
|
} |
|
|
} |
|
|
FileContent::NotFound => FileJsonContent::NotFound, |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn parse_json_with_comments_ref(&self) -> FileJsonContent { |
|
|
match self { |
|
|
FileContent::Content(file) => match file.content.to_str() { |
|
|
Ok(string) => match parse_to_serde_value( |
|
|
&string, |
|
|
&ParseOptions { |
|
|
allow_comments: true, |
|
|
allow_trailing_commas: true, |
|
|
allow_loose_object_property_names: false, |
|
|
}, |
|
|
) { |
|
|
Ok(data) => match data { |
|
|
Some(value) => FileJsonContent::Content(value), |
|
|
None => FileJsonContent::unparsable( |
|
|
"text content doesn't contain any json data", |
|
|
), |
|
|
}, |
|
|
Err(e) => FileJsonContent::Unparsable(Box::new( |
|
|
UnparsableJson::from_jsonc_error(e, string.as_ref()), |
|
|
)), |
|
|
}, |
|
|
Err(_) => FileJsonContent::unparsable("binary is not valid utf-8 text"), |
|
|
}, |
|
|
FileContent::NotFound => FileJsonContent::NotFound, |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn parse_json5_ref(&self) -> FileJsonContent { |
|
|
match self { |
|
|
FileContent::Content(file) => match file.content.to_str() { |
|
|
Ok(string) => match parse_to_serde_value( |
|
|
&string, |
|
|
&ParseOptions { |
|
|
allow_comments: true, |
|
|
allow_trailing_commas: true, |
|
|
allow_loose_object_property_names: true, |
|
|
}, |
|
|
) { |
|
|
Ok(data) => match data { |
|
|
Some(value) => FileJsonContent::Content(value), |
|
|
None => FileJsonContent::unparsable( |
|
|
"text content doesn't contain any json data", |
|
|
), |
|
|
}, |
|
|
Err(e) => FileJsonContent::Unparsable(Box::new( |
|
|
UnparsableJson::from_jsonc_error(e, string.as_ref()), |
|
|
)), |
|
|
}, |
|
|
Err(_) => FileJsonContent::unparsable("binary is not valid utf-8 text"), |
|
|
}, |
|
|
FileContent::NotFound => FileJsonContent::NotFound, |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn lines_ref(&self) -> FileLinesContent { |
|
|
match self { |
|
|
FileContent::Content(file) => match file.content.to_str() { |
|
|
Ok(string) => { |
|
|
let mut bytes_offset = 0; |
|
|
FileLinesContent::Lines( |
|
|
string |
|
|
.split('\n') |
|
|
.map(|l| { |
|
|
let line = FileLine { |
|
|
content: l.to_string(), |
|
|
bytes_offset, |
|
|
}; |
|
|
bytes_offset += (l.len() + 1) as u32; |
|
|
line |
|
|
}) |
|
|
.collect(), |
|
|
) |
|
|
} |
|
|
Err(_) => FileLinesContent::Unparsable, |
|
|
}, |
|
|
FileContent::NotFound => FileLinesContent::NotFound, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl FileContent { |
|
|
#[turbo_tasks::function] |
|
|
pub fn len(&self) -> Result<Vc<Option<u64>>> { |
|
|
Ok(Vc::cell(match self { |
|
|
FileContent::Content(file) => Some(file.content.len() as u64), |
|
|
FileContent::NotFound => None, |
|
|
})) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub fn parse_json(&self) -> Result<Vc<FileJsonContent>> { |
|
|
Ok(self.parse_json_ref().into()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn parse_json_with_comments(self: Vc<Self>) -> Result<Vc<FileJsonContent>> { |
|
|
let this = self.await?; |
|
|
Ok(this.parse_json_with_comments_ref().into()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn parse_json5(self: Vc<Self>) -> Result<Vc<FileJsonContent>> { |
|
|
let this = self.await?; |
|
|
Ok(this.parse_json5_ref().into()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn lines(self: Vc<Self>) -> Result<Vc<FileLinesContent>> { |
|
|
let this = self.await?; |
|
|
Ok(this.lines_ref().into()) |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn hash(self: Vc<Self>) -> Result<Vc<u64>> { |
|
|
Ok(Vc::cell(hash_xxh3_hash64(&self.await?))) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[turbo_tasks::value(shared, serialization = "none")] |
|
|
pub enum FileJsonContent { |
|
|
Content(Value), |
|
|
Unparsable(Box<UnparsableJson>), |
|
|
NotFound, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ValueToString for FileJsonContent { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn to_string(&self) -> Result<Vc<RcStr>> { |
|
|
match self { |
|
|
FileJsonContent::Content(json) => Ok(Vc::cell(json.to_string().into())), |
|
|
FileJsonContent::Unparsable(e) => Err(anyhow!("File is not valid JSON: {}", e)), |
|
|
FileJsonContent::NotFound => Err(anyhow!("File not found")), |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl FileJsonContent { |
|
|
#[turbo_tasks::function] |
|
|
pub async fn content(self: Vc<Self>) -> Result<Vc<Value>> { |
|
|
match &*self.await? { |
|
|
FileJsonContent::Content(json) => Ok(Vc::cell(json.clone())), |
|
|
FileJsonContent::Unparsable(e) => Err(anyhow!("File is not valid JSON: {}", e)), |
|
|
FileJsonContent::NotFound => Err(anyhow!("File not found")), |
|
|
} |
|
|
} |
|
|
} |
|
|
impl FileJsonContent { |
|
|
pub fn unparsable(message: &'static str) -> Self { |
|
|
FileJsonContent::Unparsable(Box::new(UnparsableJson { |
|
|
message: Cow::Borrowed(message), |
|
|
path: None, |
|
|
start_location: None, |
|
|
end_location: None, |
|
|
})) |
|
|
} |
|
|
|
|
|
pub fn unparsable_with_message(message: Cow<'static, str>) -> Self { |
|
|
FileJsonContent::Unparsable(Box::new(UnparsableJson { |
|
|
message, |
|
|
path: None, |
|
|
start_location: None, |
|
|
end_location: None, |
|
|
})) |
|
|
} |
|
|
} |
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)] |
|
|
pub struct FileLine { |
|
|
pub content: String, |
|
|
pub bytes_offset: u32, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared, serialization = "none")] |
|
|
pub enum FileLinesContent { |
|
|
Lines(#[turbo_tasks(trace_ignore)] Vec<FileLine>), |
|
|
Unparsable, |
|
|
NotFound, |
|
|
} |
|
|
|
|
|
#[derive(Hash, Clone, Debug, PartialEq, Eq, TraceRawVcs, Serialize, Deserialize, NonLocalValue)] |
|
|
pub enum RawDirectoryEntry { |
|
|
File, |
|
|
Directory, |
|
|
Symlink, |
|
|
Other, |
|
|
Error, |
|
|
} |
|
|
|
|
|
#[derive(Hash, Clone, Debug, PartialEq, Eq, TraceRawVcs, Serialize, Deserialize, NonLocalValue)] |
|
|
pub enum DirectoryEntry { |
|
|
File(FileSystemPath), |
|
|
Directory(FileSystemPath), |
|
|
Symlink(FileSystemPath), |
|
|
Other(FileSystemPath), |
|
|
Error, |
|
|
} |
|
|
|
|
|
impl DirectoryEntry { |
|
|
|
|
|
|
|
|
|
|
|
pub async fn resolve_symlink(self) -> Result<Self> { |
|
|
if let DirectoryEntry::Symlink(symlink) = &self { |
|
|
let real_path = symlink.realpath().owned().await?; |
|
|
match *real_path.get_type().await? { |
|
|
FileSystemEntryType::Directory => Ok(DirectoryEntry::Directory(real_path)), |
|
|
FileSystemEntryType::File => Ok(DirectoryEntry::File(real_path)), |
|
|
_ => Ok(self), |
|
|
} |
|
|
} else { |
|
|
Ok(self) |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn path(self) -> Option<FileSystemPath> { |
|
|
match self { |
|
|
DirectoryEntry::File(path) |
|
|
| DirectoryEntry::Directory(path) |
|
|
| DirectoryEntry::Symlink(path) |
|
|
| DirectoryEntry::Other(path) => Some(path), |
|
|
DirectoryEntry::Error => None, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value] |
|
|
#[derive(Hash, Clone, Copy, Debug)] |
|
|
pub enum FileSystemEntryType { |
|
|
NotFound, |
|
|
File, |
|
|
Directory, |
|
|
Symlink, |
|
|
Other, |
|
|
Error, |
|
|
} |
|
|
|
|
|
impl From<FileType> for FileSystemEntryType { |
|
|
fn from(file_type: FileType) -> Self { |
|
|
match file_type { |
|
|
t if t.is_dir() => FileSystemEntryType::Directory, |
|
|
t if t.is_file() => FileSystemEntryType::File, |
|
|
t if t.is_symlink() => FileSystemEntryType::Symlink, |
|
|
_ => FileSystemEntryType::Other, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<DirectoryEntry> for FileSystemEntryType { |
|
|
fn from(entry: DirectoryEntry) -> Self { |
|
|
FileSystemEntryType::from(&entry) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<&DirectoryEntry> for FileSystemEntryType { |
|
|
fn from(entry: &DirectoryEntry) -> Self { |
|
|
match entry { |
|
|
DirectoryEntry::File(_) => FileSystemEntryType::File, |
|
|
DirectoryEntry::Directory(_) => FileSystemEntryType::Directory, |
|
|
DirectoryEntry::Symlink(_) => FileSystemEntryType::Symlink, |
|
|
DirectoryEntry::Other(_) => FileSystemEntryType::Other, |
|
|
DirectoryEntry::Error => FileSystemEntryType::Error, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<RawDirectoryEntry> for FileSystemEntryType { |
|
|
fn from(entry: RawDirectoryEntry) -> Self { |
|
|
FileSystemEntryType::from(&entry) |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<&RawDirectoryEntry> for FileSystemEntryType { |
|
|
fn from(entry: &RawDirectoryEntry) -> Self { |
|
|
match entry { |
|
|
RawDirectoryEntry::File => FileSystemEntryType::File, |
|
|
RawDirectoryEntry::Directory => FileSystemEntryType::Directory, |
|
|
RawDirectoryEntry::Symlink => FileSystemEntryType::Symlink, |
|
|
RawDirectoryEntry::Other => FileSystemEntryType::Other, |
|
|
RawDirectoryEntry::Error => FileSystemEntryType::Error, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value] |
|
|
#[derive(Debug)] |
|
|
pub enum RawDirectoryContent { |
|
|
|
|
|
|
|
|
Entries(AutoMap<RcStr, RawDirectoryEntry>), |
|
|
NotFound, |
|
|
} |
|
|
|
|
|
impl RawDirectoryContent { |
|
|
pub fn new(entries: AutoMap<RcStr, RawDirectoryEntry>) -> Vc<Self> { |
|
|
Self::cell(RawDirectoryContent::Entries(entries)) |
|
|
} |
|
|
|
|
|
pub fn not_found() -> Vc<Self> { |
|
|
Self::cell(RawDirectoryContent::NotFound) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value] |
|
|
#[derive(Debug)] |
|
|
pub enum DirectoryContent { |
|
|
Entries(AutoMap<RcStr, DirectoryEntry>), |
|
|
NotFound, |
|
|
} |
|
|
|
|
|
impl DirectoryContent { |
|
|
pub fn new(entries: AutoMap<RcStr, DirectoryEntry>) -> Vc<Self> { |
|
|
Self::cell(DirectoryContent::Entries(entries)) |
|
|
} |
|
|
|
|
|
pub fn not_found() -> Vc<Self> { |
|
|
Self::cell(DirectoryContent::NotFound) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
pub struct NullFileSystem; |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl FileSystem for NullFileSystem { |
|
|
#[turbo_tasks::function] |
|
|
fn read(&self, _fs_path: FileSystemPath) -> Vc<FileContent> { |
|
|
FileContent::NotFound.cell() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn read_link(&self, _fs_path: FileSystemPath) -> Vc<LinkContent> { |
|
|
LinkContent::NotFound.into() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Vc<RawDirectoryContent> { |
|
|
RawDirectoryContent::not_found() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn write(&self, _fs_path: FileSystemPath, _content: Vc<FileContent>) -> Vc<()> { |
|
|
Vc::default() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn write_link(&self, _fs_path: FileSystemPath, _target: Vc<LinkContent>) -> Vc<()> { |
|
|
Vc::default() |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn metadata(&self, _fs_path: FileSystemPath) -> Vc<FileMeta> { |
|
|
FileMeta::default().cell() |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ValueToString for NullFileSystem { |
|
|
#[turbo_tasks::function] |
|
|
fn to_string(&self) -> Vc<RcStr> { |
|
|
Vc::cell(rcstr!("null")) |
|
|
} |
|
|
} |
|
|
|
|
|
pub async fn to_sys_path(mut path: FileSystemPath) -> Result<Option<PathBuf>> { |
|
|
loop { |
|
|
if let Some(fs) = Vc::try_resolve_downcast_type::<AttachedFileSystem>(path.fs()).await? { |
|
|
path = fs.get_inner_fs_path(path).owned().await?; |
|
|
continue; |
|
|
} |
|
|
|
|
|
if let Some(fs) = Vc::try_resolve_downcast_type::<DiskFileSystem>(path.fs()).await? { |
|
|
let sys_path = fs.await?.to_sys_path(path).await?; |
|
|
return Ok(Some(sys_path)); |
|
|
} |
|
|
|
|
|
return Ok(None); |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn read_dir(path: FileSystemPath) -> Result<Vc<DirectoryContent>> { |
|
|
let fs = path.fs().to_resolved().await?; |
|
|
match &*fs.raw_read_dir(path.clone()).await? { |
|
|
RawDirectoryContent::NotFound => Ok(DirectoryContent::not_found()), |
|
|
RawDirectoryContent::Entries(entries) => { |
|
|
let mut normalized_entries = AutoMap::new(); |
|
|
let dir_path = &path.path; |
|
|
for (name, entry) in entries { |
|
|
|
|
|
|
|
|
|
|
|
let path = if dir_path.is_empty() { |
|
|
name.clone() |
|
|
} else { |
|
|
RcStr::from(format!("{dir_path}/{name}")) |
|
|
}; |
|
|
|
|
|
let entry_path = FileSystemPath::new_normalized(fs, path); |
|
|
let entry = match entry { |
|
|
RawDirectoryEntry::File => DirectoryEntry::File(entry_path), |
|
|
RawDirectoryEntry::Directory => DirectoryEntry::Directory(entry_path), |
|
|
RawDirectoryEntry::Symlink => DirectoryEntry::Symlink(entry_path), |
|
|
RawDirectoryEntry::Other => DirectoryEntry::Other(entry_path), |
|
|
RawDirectoryEntry::Error => DirectoryEntry::Error, |
|
|
}; |
|
|
normalized_entries.insert(name.clone(), entry); |
|
|
} |
|
|
Ok(DirectoryContent::new(normalized_entries)) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn get_type(path: FileSystemPath) -> Result<Vc<FileSystemEntryType>> { |
|
|
if path.is_root() { |
|
|
return Ok(FileSystemEntryType::Directory.cell()); |
|
|
} |
|
|
let parent = path.parent(); |
|
|
let dir_content = parent.raw_read_dir().await?; |
|
|
match &*dir_content { |
|
|
RawDirectoryContent::NotFound => Ok(FileSystemEntryType::NotFound.cell()), |
|
|
RawDirectoryContent::Entries(entries) => { |
|
|
let (_, file_name) = path.split_file_name(); |
|
|
if let Some(entry) = entries.get(file_name) { |
|
|
Ok(FileSystemEntryType::from(entry).cell()) |
|
|
} else { |
|
|
Ok(FileSystemEntryType::NotFound.cell()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
async fn realpath_with_links(path: FileSystemPath) -> Result<Vc<RealPathResult>> { |
|
|
let mut current_vc = path.clone(); |
|
|
let mut symlinks: IndexSet<FileSystemPath> = IndexSet::new(); |
|
|
let mut visited: AutoSet<RcStr> = AutoSet::new(); |
|
|
|
|
|
|
|
|
for _i in 0..40 { |
|
|
let current = current_vc.clone(); |
|
|
if current.is_root() { |
|
|
|
|
|
return Ok(RealPathResult { |
|
|
path: current_vc, |
|
|
symlinks: symlinks.into_iter().collect(), |
|
|
} |
|
|
.cell()); |
|
|
} |
|
|
|
|
|
if !visited.insert(current.path.clone()) { |
|
|
break; |
|
|
} |
|
|
|
|
|
|
|
|
let parent = current_vc.parent(); |
|
|
let parent_result = parent.realpath_with_links().owned().await?; |
|
|
let basename = current |
|
|
.path |
|
|
.rsplit_once('/') |
|
|
.map_or(current.path.as_str(), |(_, name)| name); |
|
|
if parent_result.path != parent { |
|
|
current_vc = parent_result.path.join(basename)?; |
|
|
} |
|
|
symlinks.extend(parent_result.symlinks); |
|
|
|
|
|
|
|
|
|
|
|
if !matches!(*current_vc.get_type().await?, FileSystemEntryType::Symlink) { |
|
|
return Ok(RealPathResult { |
|
|
path: current_vc, |
|
|
symlinks: symlinks.into_iter().collect(), |
|
|
} |
|
|
.cell()); |
|
|
} |
|
|
|
|
|
if let LinkContent::Link { target, link_type } = &*current_vc.read_link().await? { |
|
|
symlinks.insert(current_vc.clone()); |
|
|
current_vc = if link_type.contains(LinkType::ABSOLUTE) { |
|
|
current_vc.root().owned().await? |
|
|
} else { |
|
|
parent_result.path |
|
|
} |
|
|
.join(target)?; |
|
|
} else { |
|
|
|
|
|
|
|
|
return Ok(RealPathResult { |
|
|
path: current_vc, |
|
|
symlinks: symlinks.into_iter().collect(), |
|
|
} |
|
|
.cell()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(RealPathResult { |
|
|
path, |
|
|
symlinks: symlinks.into_iter().collect(), |
|
|
} |
|
|
.cell()) |
|
|
} |
|
|
|
|
|
pub fn register() { |
|
|
turbo_tasks::register(); |
|
|
include!(concat!(env!("OUT_DIR"), "/register.rs")); |
|
|
} |
|
|
|
|
|
#[cfg(test)] |
|
|
mod tests { |
|
|
use turbo_rcstr::rcstr; |
|
|
|
|
|
use super::*; |
|
|
|
|
|
#[test] |
|
|
fn test_get_relative_path_to() { |
|
|
assert_eq!(get_relative_path_to("a/b/c", "a/b/c").as_str(), "."); |
|
|
assert_eq!(get_relative_path_to("a/c/d", "a/b/c").as_str(), "../../b/c"); |
|
|
assert_eq!(get_relative_path_to("", "a/b/c").as_str(), "./a/b/c"); |
|
|
assert_eq!(get_relative_path_to("a/b/c", "").as_str(), "../../.."); |
|
|
assert_eq!( |
|
|
get_relative_path_to("a/b/c", "c/b/a").as_str(), |
|
|
"../../../c/b/a" |
|
|
); |
|
|
assert_eq!( |
|
|
get_relative_path_to("file:///a/b/c", "file:///c/b/a").as_str(), |
|
|
"../../../c/b/a" |
|
|
); |
|
|
} |
|
|
|
|
|
#[tokio::test] |
|
|
async fn with_extension() { |
|
|
crate::register(); |
|
|
|
|
|
turbo_tasks_testing::VcStorage::with(async { |
|
|
let fs = Vc::upcast::<Box<dyn FileSystem>>(VirtualFileSystem::new()) |
|
|
.to_resolved() |
|
|
.await?; |
|
|
|
|
|
let path_txt = FileSystemPath::new_normalized(fs, rcstr!("foo/bar.txt")); |
|
|
|
|
|
let path_json = path_txt.with_extension("json"); |
|
|
assert_eq!(&*path_json.path, "foo/bar.json"); |
|
|
|
|
|
let path_no_ext = path_txt.with_extension(""); |
|
|
assert_eq!(&*path_no_ext.path, "foo/bar"); |
|
|
|
|
|
let path_new_ext = path_no_ext.with_extension("json"); |
|
|
assert_eq!(&*path_new_ext.path, "foo/bar.json"); |
|
|
|
|
|
let path_no_slash_txt = FileSystemPath::new_normalized(fs, rcstr!("bar.txt")); |
|
|
|
|
|
let path_no_slash_json = path_no_slash_txt.with_extension("json"); |
|
|
assert_eq!(path_no_slash_json.path.as_str(), "bar.json"); |
|
|
|
|
|
let path_no_slash_no_ext = path_no_slash_txt.with_extension(""); |
|
|
assert_eq!(path_no_slash_no_ext.path.as_str(), "bar"); |
|
|
|
|
|
let path_no_slash_new_ext = path_no_slash_no_ext.with_extension("json"); |
|
|
assert_eq!(path_no_slash_new_ext.path.as_str(), "bar.json"); |
|
|
|
|
|
anyhow::Ok(()) |
|
|
}) |
|
|
.await |
|
|
.unwrap() |
|
|
} |
|
|
|
|
|
#[tokio::test] |
|
|
async fn file_stem() { |
|
|
crate::register(); |
|
|
|
|
|
turbo_tasks_testing::VcStorage::with(async { |
|
|
let fs = Vc::upcast::<Box<dyn FileSystem>>(VirtualFileSystem::new()) |
|
|
.to_resolved() |
|
|
.await?; |
|
|
|
|
|
let path = FileSystemPath::new_normalized(fs, rcstr!("")); |
|
|
assert_eq!(path.file_stem(), None); |
|
|
|
|
|
let path = FileSystemPath::new_normalized(fs, rcstr!("foo/bar.txt")); |
|
|
assert_eq!(path.file_stem(), Some("bar")); |
|
|
|
|
|
let path = FileSystemPath::new_normalized(fs, rcstr!("bar.txt")); |
|
|
assert_eq!(path.file_stem(), Some("bar")); |
|
|
|
|
|
let path = FileSystemPath::new_normalized(fs, rcstr!("foo/bar")); |
|
|
assert_eq!(path.file_stem(), Some("bar")); |
|
|
|
|
|
let path = FileSystemPath::new_normalized(fs, rcstr!("foo/.bar")); |
|
|
assert_eq!(path.file_stem(), Some(".bar")); |
|
|
|
|
|
anyhow::Ok(()) |
|
|
}) |
|
|
.await |
|
|
.unwrap() |
|
|
} |
|
|
} |
|
|
|