diff --git a/yazi-adaptor/src/adaptor.rs b/yazi-adaptor/src/adaptor.rs index e3b111bc..a00bbaf9 100644 --- a/yazi-adaptor/src/adaptor.rs +++ b/yazi-adaptor/src/adaptor.rs @@ -170,7 +170,7 @@ impl Adaptor { pub async fn image_show(self, mut path: &Path, rect: Rect) -> Result<()> { let cache = PREVIEW.cache(path, 0); - if fs::metadata(&cache).await.is_ok() { + if fs::symlink_metadata(&cache).await.is_ok() { path = cache.as_path(); } diff --git a/yazi-adaptor/src/image.rs b/yazi-adaptor/src/image.rs index 1052f21e..4f290a73 100644 --- a/yazi-adaptor/src/image.rs +++ b/yazi-adaptor/src/image.rs @@ -9,7 +9,7 @@ use yazi_shared::Term; pub struct Image; impl Image { - pub(super) async fn crop(path: &Path, size: (u16, u16)) -> Result { + pub(super) async fn downscale(path: &Path, size: (u16, u16)) -> Result { let (w, h) = Term::ratio() .map(|(w, h)| { let (w, h) = ((size.0 as f64 * w) as u32, (size.1 as f64 * h) as u32); @@ -30,33 +30,19 @@ impl Image { img.await? } - pub async fn precache(img: Arc>, cache: impl AsRef) -> Result { + pub async fn precache(img: Arc>, cache: impl AsRef) -> Result<()> { let cache = cache.as_ref().to_owned(); let result = tokio::task::spawn_blocking(move || { let img = image::load_from_memory(&img)?; let (w, h) = (PREVIEW.max_width, PREVIEW.max_height); - if img.width() <= w && img.height() <= h { - return Ok(false); - } - - match img.resize(w, h, FilterType::Triangle) { + Ok(match img.resize(w, h, FilterType::Triangle) { DynamicImage::ImageRgb8(buf) => buf.save_with_format(cache, ImageFormat::Jpeg), DynamicImage::ImageRgba8(buf) => buf.save_with_format(cache, ImageFormat::Jpeg), buf => buf.to_rgb8().save_with_format(cache, ImageFormat::Jpeg), - }?; - - Ok(true) + }?) }); result.await? } - - #[inline] - pub async fn precache_anyway(img: Arc>, cache: impl AsRef) -> Result<()> { - Ok(match Self::precache(img.clone(), &cache).await { - Ok(true) => (), - _ => fs::write(cache, &*img).await?, - }) - } } diff --git a/yazi-adaptor/src/iterm2.rs b/yazi-adaptor/src/iterm2.rs index 81b47a3a..d1655135 100644 --- a/yazi-adaptor/src/iterm2.rs +++ b/yazi-adaptor/src/iterm2.rs @@ -13,7 +13,7 @@ pub(super) struct Iterm2; impl Iterm2 { pub(super) async fn image_show(path: &Path, rect: Rect) -> Result<()> { - let img = Image::crop(path, (rect.width, rect.height)).await?; + let img = Image::downscale(path, (rect.width, rect.height)).await?; let b = Self::encode(img).await?; Self::image_hide(rect)?; diff --git a/yazi-adaptor/src/kitty.rs b/yazi-adaptor/src/kitty.rs index 6640b957..64686a90 100644 --- a/yazi-adaptor/src/kitty.rs +++ b/yazi-adaptor/src/kitty.rs @@ -313,7 +313,7 @@ pub(super) struct Kitty; impl Kitty { pub(super) async fn image_show(path: &Path, rect: Rect) -> Result<()> { - let img = Image::crop(path, (rect.width, rect.height)).await?; + let img = Image::downscale(path, (rect.width, rect.height)).await?; let b = Self::encode(img).await?; Self::image_hide(rect)?; diff --git a/yazi-adaptor/src/kitty_old.rs b/yazi-adaptor/src/kitty_old.rs index 5cfe1bbc..72e9f2fa 100644 --- a/yazi-adaptor/src/kitty_old.rs +++ b/yazi-adaptor/src/kitty_old.rs @@ -13,7 +13,7 @@ pub(super) struct KittyOld; impl KittyOld { pub(super) async fn image_show(path: &Path, rect: Rect) -> Result<()> { - let img = Image::crop(path, (rect.width, rect.height)).await?; + let img = Image::downscale(path, (rect.width, rect.height)).await?; let b = Self::encode(img).await?; Self::image_hide()?; diff --git a/yazi-adaptor/src/sixel.rs b/yazi-adaptor/src/sixel.rs index b89b48e3..feb90ed8 100644 --- a/yazi-adaptor/src/sixel.rs +++ b/yazi-adaptor/src/sixel.rs @@ -12,7 +12,7 @@ pub(super) struct Sixel; impl Sixel { pub(super) async fn image_show(path: &Path, rect: Rect) -> Result<()> { - let img = Image::crop(path, (rect.width, rect.height)).await?; + let img = Image::downscale(path, (rect.width, rect.height)).await?; let b = Self::encode(img).await?; Self::image_hide(rect)?; diff --git a/yazi-core/src/external/pdftoppm.rs b/yazi-core/src/external/pdftoppm.rs index 3f9c4c1d..8ea0f383 100644 --- a/yazi-core/src/external/pdftoppm.rs +++ b/yazi-core/src/external/pdftoppm.rs @@ -25,5 +25,5 @@ pub async fn pdftoppm(src: &Path, dest: impl AsRef, skip: usize) -> Result return if pages > 0 { Err(PeekError::Exceed(pages - 1)) } else { Err(s.to_string().into()) }; } - Ok(Image::precache_anyway(Arc::new(output.stdout), dest).await?) + Ok(Image::precache(Arc::new(output.stdout), dest).await?) } diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index 23dcc608..35a4f7aa 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -144,7 +144,7 @@ impl Manager { let mut failed = Vec::new(); for (o, n) in todo { - if fs::metadata(&n).await.is_ok() { + if fs::symlink_metadata(&n).await.is_ok() { failed.push((o, n, anyhow!("Destination already exists"))); continue; } diff --git a/yazi-core/src/preview/provider.rs b/yazi-core/src/preview/provider.rs index 586392df..d3bc6a42 100644 --- a/yazi-core/src/preview/provider.rs +++ b/yazi-core/src/preview/provider.rs @@ -48,7 +48,7 @@ impl Provider { pub(super) async fn video(path: &Path, skip: usize) -> Result { let cache = PREVIEW.cache(path, skip); - if fs::metadata(&cache).await.is_err() { + if fs::symlink_metadata(&cache).await.is_err() { external::ffmpegthumbnailer(path, &cache, skip).await?; } @@ -57,7 +57,7 @@ impl Provider { pub(super) async fn pdf(path: &Path, skip: usize) -> Result { let cache = PREVIEW.cache(path, skip); - if fs::metadata(&cache).await.is_err() { + if fs::symlink_metadata(&cache).await.is_err() { external::pdftoppm(path, &cache, skip).await?; } diff --git a/yazi-core/src/tasks/workers/precache.rs b/yazi-core/src/tasks/workers/precache.rs index cf3337aa..204dc8f2 100644 --- a/yazi-core/src/tasks/workers/precache.rs +++ b/yazi-core/src/tasks/workers/precache.rs @@ -75,7 +75,7 @@ impl Precache { match task { PrecacheOp::Image(task) => { let cache = PREVIEW.cache(&task.target, 0); - if fs::metadata(&cache).await.is_ok() { + if fs::symlink_metadata(&cache).await.is_ok() { return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?); } if let Ok(img) = fs::read(&task.target).await { @@ -85,7 +85,7 @@ impl Precache { } PrecacheOp::Video(task) => { let cache = PREVIEW.cache(&task.target, 0); - if fs::metadata(&cache).await.is_ok() { + if fs::symlink_metadata(&cache).await.is_ok() { return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?); } @@ -94,7 +94,7 @@ impl Precache { } PrecacheOp::Pdf(task) => { let cache = PREVIEW.cache(&task.target, 0); - if fs::metadata(&cache).await.is_ok() { + if fs::symlink_metadata(&cache).await.is_ok() { return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?); }