mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
Some checks are pending
Cachix / Publish Flake (push) Waiting to run
Check / clippy (push) Waiting to run
Check / rustfmt (push) Waiting to run
Check / stylua (push) Waiting to run
Draft / build-unix (gcc-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-riscv64-linux-gnu, ubuntu-latest, riscv64gc-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-sparc64-linux-gnu, ubuntu-latest, sparc64-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (macos-latest, aarch64-apple-darwin) (push) Waiting to run
Draft / build-unix (macos-latest, x86_64-apple-darwin) (push) Waiting to run
Draft / build-unix (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Waiting to run
Draft / build-windows (windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Draft / build-windows (windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Draft / build-musl (aarch64-unknown-linux-musl) (push) Waiting to run
Draft / build-musl (x86_64-unknown-linux-musl) (push) Waiting to run
Draft / build-snap (amd64, ubuntu-latest) (push) Waiting to run
Draft / build-snap (arm64, ubuntu-24.04-arm) (push) Waiting to run
Draft / snap (push) Blocked by required conditions
Draft / draft (push) Blocked by required conditions
Draft / nightly (push) Blocked by required conditions
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run
36 lines
892 B
Rust
36 lines
892 B
Rust
use std::hash::Hash;
|
|
|
|
use mlua::{Function, Lua, Table};
|
|
use yazi_config::YAZI;
|
|
use yazi_fs::{FsHash128, file::{FileRef, FileSig}};
|
|
use yazi_shared::url::{Url, UrlBuf, UrlLike};
|
|
use yazi_shim::Twox128;
|
|
|
|
use super::Utils;
|
|
|
|
impl Utils {
|
|
pub(super) fn file_cache(lua: &Lua) -> mlua::Result<Function> {
|
|
struct Sig<'a>(FileSig<'a>, usize);
|
|
|
|
impl FsHash128 for Sig<'_> {
|
|
fn hash_u128(&self) -> u128 {
|
|
let mut h = Twox128::default();
|
|
self.0.hash(&mut h);
|
|
self.1.hash(&mut h);
|
|
h.finish_128()
|
|
}
|
|
}
|
|
|
|
lua.create_function(|_, t: Table| {
|
|
let file: FileRef = t.raw_get("file")?;
|
|
file.borrow(|f| {
|
|
if f.url.parent() == Some(Url::regular(&YAZI.preview.cache_dir)) {
|
|
return Ok(None);
|
|
}
|
|
|
|
let sig = Sig(FileSig(f), t.raw_get("skip").unwrap_or_default());
|
|
Ok(Some(UrlBuf::from(YAZI.preview.cache_dir.join(sig.hash_base32(&mut [0; 26])))))
|
|
})
|
|
})
|
|
}
|
|
}
|