mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Some checks failed
Cachix / Publish Flake (push) Has been cancelled
Check / clippy (push) Has been cancelled
Check / rustfmt (push) Has been cancelled
Check / stylua (push) Has been cancelled
Draft / build-unix (gcc-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-riscv64-linux-gnu, ubuntu-latest, riscv64gc-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (gcc-sparc64-linux-gnu, ubuntu-latest, sparc64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-unix (macos-latest, aarch64-apple-darwin) (push) Has been cancelled
Draft / build-unix (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Draft / build-unix (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Draft / build-windows (windows-latest, aarch64-pc-windows-msvc) (push) Has been cancelled
Draft / build-windows (windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Draft / build-musl (aarch64-unknown-linux-musl) (push) Has been cancelled
Draft / build-musl (x86_64-unknown-linux-musl) (push) Has been cancelled
Draft / build-snap (amd64, ubuntu-latest) (push) Has been cancelled
Draft / build-snap (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (macos-latest) (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
Test / test (windows-latest) (push) Has been cancelled
Draft / snap (push) Has been cancelled
Draft / draft (push) Has been cancelled
Draft / nightly (push) Has been cancelled
43 lines
1 KiB
Rust
43 lines
1 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use yazi_shared::{auth::{Auth, AuthKind}, path::PathBufDyn, spec::SpecInventory};
|
|
use yazi_shim::{mlua::UserDataFieldsExt, strum::IntoStr};
|
|
|
|
use crate::{FsHash128, Xdg};
|
|
|
|
pub trait FsAuth {
|
|
fn cache_root(&self) -> Option<PathBuf>;
|
|
|
|
fn stamp_root(&self) -> Option<PathBuf> {
|
|
self.cache_root().map(|mut root| {
|
|
root.push("%stamp");
|
|
root
|
|
})
|
|
}
|
|
}
|
|
|
|
impl FsAuth for Auth {
|
|
fn cache_root(&self) -> Option<PathBuf> {
|
|
match self.kind {
|
|
AuthKind::Regular | AuthKind::Search => None,
|
|
AuthKind::Mount | AuthKind::Hub | AuthKind::Scope | AuthKind::Sftp => {
|
|
Some(Xdg::temp_dir().join(format!(
|
|
"{}_{}_{}",
|
|
self.kind.into_str(),
|
|
self.scheme,
|
|
self.domain.hash_u128_str(&mut [0; 26])
|
|
)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Inject
|
|
inventory::submit! {
|
|
SpecInventory {
|
|
register: |registry| {
|
|
registry.add_cached_field("cache", |_, me| Ok(me.cache_root().map(PathBufDyn::from)));
|
|
registry.add_cached_field("stamp", |_, me| Ok(me.stamp_root().map(PathBufDyn::from)));
|
|
}
|
|
}
|
|
}
|