mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41: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
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
use std::{ffi::OsString, io, path::{Component, PathBuf}};
|
|
|
|
use mlua::{BorrowedBytes, FromLua, IntoLua, Lua, Table, Value};
|
|
use yazi_shared::{path::PathBufDyn, strand::AsStrand};
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct TrashNode {
|
|
pub(super) key: OsString,
|
|
pub(super) top: OsString,
|
|
pub(super) rel: PathBuf,
|
|
}
|
|
|
|
impl TrashNode {
|
|
pub(super) fn validate(&self) -> io::Result<()> {
|
|
if self.key.is_empty() || self.top.is_empty() || !self.rel.is_relative() {
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid trash node"));
|
|
}
|
|
if self.rel.components().any(|c| matches!(c, Component::ParentDir)) {
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid trash node path"));
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl FromLua for TrashNode {
|
|
fn from_lua(value: Value, lua: &Lua) -> mlua::Result<Self> {
|
|
let t = Table::from_lua(value, lua)?;
|
|
let node = Self {
|
|
key: t.raw_get::<BorrowedBytes>("key")?.as_strand().to_os_string()?,
|
|
top: t.raw_get::<BorrowedBytes>("top")?.as_strand().to_os_string()?,
|
|
rel: t.raw_get::<PathBufDyn>("rel")?.into_os()?,
|
|
};
|
|
|
|
node.validate().map_err(mlua::Error::external)?;
|
|
Ok(node)
|
|
}
|
|
}
|
|
|
|
impl IntoLua for TrashNode {
|
|
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
|
|
lua
|
|
.create_table_from([
|
|
("key", lua.create_external_string(self.key.into_encoded_bytes())?.into_lua(lua)?),
|
|
("top", lua.create_external_string(self.top.into_encoded_bytes())?.into_lua(lua)?),
|
|
("rel", PathBufDyn::from(self.rel).into_lua(lua)?),
|
|
])?
|
|
.into_lua(lua)
|
|
}
|
|
}
|