0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

perf(node/fs/copy): reduce metadata lookups copying directory (#27495)

This commit is contained in:
David Sherret 2024-12-30 00:36:29 -05:00 committed by GitHub
parent 5194222e02
commit fd8400eaec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -723,8 +723,9 @@ fn cp(from: &Path, to: &Path) -> FsResult<()> {
} }
} }
match (fs::metadata(to), fs::symlink_metadata(to)) { if let Ok(m) = fs::metadata(to) {
(Ok(m), _) if m.is_dir() => cp_( if m.is_dir() {
return cp_(
source_meta, source_meta,
from, from,
&to.join(from.file_name().ok_or_else(|| { &to.join(from.file_name().ok_or_else(|| {
@ -733,20 +734,23 @@ fn cp(from: &Path, to: &Path) -> FsResult<()> {
"the source path is not a valid file", "the source path is not a valid file",
) )
})?), })?),
)?, );
(_, Ok(m)) if is_identical(&source_meta, &m) => { }
}
if let Ok(m) = fs::symlink_metadata(to) {
if is_identical(&source_meta, &m) {
return Err( return Err(
io::Error::new( io::Error::new(
io::ErrorKind::InvalidInput, io::ErrorKind::InvalidInput,
"the source and destination are the same file", "the source and destination are the same file",
) )
.into(), .into(),
) );
} }
_ => cp_(source_meta, from, to)?,
} }
Ok(()) cp_(source_meta, from, to)
} }
#[cfg(not(windows))] #[cfg(not(windows))]