Skip to content

Commit

Permalink
feat: support displaying files with inaccessible metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Ape authored and sxyazi committed Jul 14, 2024
1 parent 2cf722e commit 966d478
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 95 deletions.
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","subsec"],"version":"0.2"}
{"version":"0.2","language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink"],"flagWords":[]}
5 changes: 5 additions & 0 deletions yazi-config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ rules = [
{ name = "*", is = "orphan", bg = "red" },
{ name = "*", is = "exec" , fg = "green" },

# Dummy files
{ name = "*", is = "dummy", bg = "red" },
{ name = "*/", is = "dummy", bg = "red" },

# Fallback
# { name = "*", fg = "white" },
{ name = "*/", fg = "blue" }
Expand Down Expand Up @@ -771,6 +775,7 @@ conds = [
{ if = "fifo" , text = "" },
{ if = "sock" , text = "" },
{ if = "sticky", text = "" },
{ if = "dummy", text = "" },

# Fallback
{ if = "dir", text = "󰉋" },
Expand Down
1 change: 1 addition & 0 deletions yazi-config/src/theme/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl Icons {
"hidden" => file.is_hidden(),
"link" => file.is_link(),
"orphan" => file.is_orphan(),
"dummy" => file.is_dummy(),
"block" => file.is_block(),
"char" => file.is_char(),
"fifo" => file.is_fifo(),
Expand Down
21 changes: 12 additions & 9 deletions yazi-config/src/theme/is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use yazi_shared::fs::Cha;
pub enum Is {
#[default]
None,
Link,
Orphan,
Dummy,
Block,
Char,
Exec,
Fifo,
Link,
Orphan,
Sock,
Exec,
Sticky,
}

Expand All @@ -24,13 +25,14 @@ impl FromStr for Is {

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"link" => Self::Link,
"orphan" => Self::Orphan,
"dummy" => Self::Dummy,
"block" => Self::Block,
"char" => Self::Char,
"exec" => Self::Exec,
"fifo" => Self::Fifo,
"link" => Self::Link,
"orphan" => Self::Orphan,
"sock" => Self::Sock,
"exec" => Self::Exec,
"sticky" => Self::Sticky,
_ => bail!("invalid filetype: {s}"),
})
Expand All @@ -48,13 +50,14 @@ impl Is {
pub fn check(&self, cha: &Cha) -> bool {
match self {
Self::None => true,
Self::Link => cha.is_link(),
Self::Orphan => cha.is_orphan(),
Self::Dummy => cha.is_dummy(),
Self::Block => cha.is_block(),
Self::Char => cha.is_char(),
Self::Exec => cha.is_exec(),
Self::Fifo => cha.is_fifo(),
Self::Link => cha.is_link(),
Self::Orphan => cha.is_orphan(),
Self::Sock => cha.is_sock(),
Self::Exec => cha.is_exec(),
Self::Sticky => cha.is_sticky(),
}
}
Expand Down
16 changes: 10 additions & 6 deletions yazi-core/src/folder/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ impl Files {
select! {
_ = tx.closed() => break,
result = item.metadata() => {
if let Ok(meta) = result {
tx.send(File::from_meta(Url::from(item.path()), meta).await).ok();
}
let url = Url::from(item.path());
_ = tx.send(match result {
Ok(meta) => File::from_meta(url, meta).await,
Err(_) => File::from_dummy(url, item.file_type().await.ok())
});
}
}
}
Expand All @@ -76,9 +78,11 @@ impl Files {
async fn go(entities: &[DirEntry]) -> Vec<File> {
let mut files = Vec::with_capacity(entities.len() / 3 + 1);
for entry in entities {
if let Ok(meta) = entry.metadata().await {
files.push(File::from_meta(Url::from(entry.path()), meta).await);
}
let url = Url::from(entry.path());
files.push(match entry.metadata().await {
Ok(meta) => File::from_meta(url, meta).await,
Err(_) => File::from_dummy(url, entry.file_type().await.ok()),
});
}
files
}
Expand Down
4 changes: 2 additions & 2 deletions yazi-core/src/folder/sorter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl FilesSorter {
match self.by {
SortBy::None => {}
SortBy::Modified => items.sort_unstable_by(|a, b| {
let ord = self.cmp(a.modified, b.modified, self.promote(a, b));
let ord = self.cmp(a.mtime, b.mtime, self.promote(a, b));
if ord == Ordering::Equal { by_alphabetical(a, b) } else { ord }
}),
SortBy::Created => items.sort_unstable_by(|a, b| {
let ord = self.cmp(a.created, b.created, self.promote(a, b));
let ord = self.cmp(a.ctime, b.ctime, self.promote(a, b));
if ord == Ordering::Equal { by_alphabetical(a, b) } else { ord }
}),
SortBy::Extension => items.sort_unstable_by(|a, b| {
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/tab/commands/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Tab {
};

self.cd(parent.clone());
FilesOp::Creating(parent, vec![File::from_dummy(&opt.target)]).emit();
FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone(), None)]).emit();
ManagerProxy::hover(Some(opt.target));
}
}
4 changes: 2 additions & 2 deletions yazi-core/src/tab/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ impl Preview {
*url == lock.url
&& self.skip == lock.skip
&& cha.len == lock.cha.len
&& cha.modified == lock.cha.modified
&& cha.mtime == lock.cha.mtime
&& cha.kind == lock.cha.kind
&& {
#[cfg(unix)]
{
cha.permissions == lock.cha.permissions
cha.perm == lock.cha.perm
}
#[cfg(windows)]
{
Expand Down
8 changes: 3 additions & 5 deletions yazi-plugin/preset/components/linemode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ end
function Linemode:permissions(file) return ui.Line(file.cha:permissions() or "") end

function Linemode:owner(file)
if not ya.user_name then
return ui.Line("")
else
return ui.Line(ya.user_name(file.cha.uid) .. ":" .. ya.group_name(file.cha.gid))
end
local user = file.cha.uid and ya.user_name(file.cha.uid) or file.cha.uid
local group = file.cha.gid and ya.group_name(file.cha.gid) or file.cha.gid
return ui.Line(string.format("%s:%s", user or "-", group or "-"))
end

function Linemode:render(files)
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/components/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Status:permissions()
for i = 1, #perm do
local c = perm:sub(i, i)
local style = THEME.status.permissions_t
if c == "-" then
if c == "-" or c == "?" then
style = THEME.status.permissions_s
elseif c == "r" then
style = THEME.status.permissions_r
Expand Down
23 changes: 12 additions & 11 deletions yazi-plugin/src/cha/cha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl Cha {
reg.add_field_method_get("is_hidden", |_, me| Ok(me.is_hidden()));
reg.add_field_method_get("is_link", |_, me| Ok(me.is_link()));
reg.add_field_method_get("is_orphan", |_, me| Ok(me.is_orphan()));
reg.add_field_method_get("is_dummy", |_, me| Ok(me.is_dummy()));
reg.add_field_method_get("is_block", |_, me| Ok(me.is_block()));
reg.add_field_method_get("is_char", |_, me| Ok(me.is_char()));
reg.add_field_method_get("is_fifo", |_, me| Ok(me.is_fifo()));
Expand All @@ -25,25 +26,25 @@ impl Cha {

#[cfg(unix)]
{
reg.add_field_method_get("uid", |_, me| Ok(me.uid));
reg.add_field_method_get("gid", |_, me| Ok(me.gid));
reg.add_field_method_get("nlink", |_, me| Ok(me.nlink));
reg.add_field_method_get("uid", |_, me| Ok((!me.is_dummy()).then_some(me.uid)));
reg.add_field_method_get("gid", |_, me| Ok((!me.is_dummy()).then_some(me.gid)));
reg.add_field_method_get("nlink", |_, me| Ok((!me.is_dummy()).then_some(me.nlink)));
}

reg.add_field_method_get("length", |_, me| Ok(me.len));
reg.add_field_method_get("created", |_, me| {
Ok(me.created.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()))
Ok(me.ctime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()))
});
reg.add_field_method_get("modified", |_, me| {
Ok(me.modified.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()))
Ok(me.mtime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()))
});
reg.add_field_method_get("accessed", |_, me| {
Ok(me.accessed.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()))
Ok(me.atime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()))
});
reg.add_method("permissions", |_, me, ()| {
Ok(
#[cfg(unix)]
Some(yazi_shared::fs::permissions(me.permissions)),
Some(yazi_shared::fs::permissions(me.perm, me.is_dummy())),
#[cfg(windows)]
None::<String>,
)
Expand Down Expand Up @@ -72,11 +73,11 @@ impl Cha {
Self::cast(lua, yazi_shared::fs::Cha {
kind,
len: t.raw_get("len").unwrap_or_default(),
accessed: parse_time(t.raw_get("atime").ok())?,
created: parse_time(t.raw_get("ctime").ok())?,
modified: parse_time(t.raw_get("mtime").ok())?,
atime: parse_time(t.raw_get("atime").ok())?,
ctime: parse_time(t.raw_get("ctime").ok())?,
mtime: parse_time(t.raw_get("mtime").ok())?,
#[cfg(unix)]
permissions: t.raw_get("permissions").unwrap_or_default(),
perm: t.raw_get("permissions").unwrap_or_default(),
#[cfg(unix)]
uid: t.raw_get("uid").unwrap_or_default(),
#[cfg(unix)]
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/src/utils/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Utils {

let hex = {
let mut digest = Md5::new_with_prefix(file.url.as_os_str().as_encoded_bytes());
digest.update(&format!("//{:?}//{}", file.cha.modified, t.raw_get("skip").unwrap_or(0)));
digest.update(&format!("//{:?}//{}", file.cha.mtime, t.raw_get("skip").unwrap_or(0)));
format!("{:x}", digest.finalize())
};

Expand Down
Loading

0 comments on commit 966d478

Please sign in to comment.