From 311ca77fda98055ecb7b5fcd73d9527f88cc6e21 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 19 Jul 2023 09:08:36 +0800 Subject: [PATCH] fix: build error on linux --- Cargo.lock | 1 + Cargo.toml | 4 ++-- build.sh | 11 +++++++++++ src/config/preset.rs | 26 ++++++++++++-------------- src/core/external/lsar.rs | 2 -- src/core/manager/folder.rs | 6 +++--- src/core/manager/tab.rs | 6 ++++-- src/core/tasks/file.rs | 2 +- src/core/tasks/tasks.rs | 9 +++++++-- src/misc/fs.rs | 4 ++++ src/ui/status/progress.rs | 1 - 11 files changed, 45 insertions(+), 27 deletions(-) create mode 100755 build.sh diff --git a/Cargo.lock b/Cargo.lock index 8cf5c6a7..c9d1bf43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1847,6 +1847,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" dependencies = [ + "indexmap 2.0.0", "serde", "serde_spanned", "toml_datetime", diff --git a/Cargo.toml b/Cargo.toml index 937fdb56..7665ac93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,8 @@ serde = { version = "^1", features = [ "derive" ] } serde_json = "^1" signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] } syntect = "^5" -tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "fs", "process", "io-std", "io-util", "time" ] } -toml = "^0" +tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "fs", "process", "io-std", "io-util" ] } +toml = { version = "^0", features = [ "preserve_order" ] } tracing = "^0" tracing-appender = "^0" tracing-subscriber = "^0" diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..78639b65 --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +cargo build --release --target aarch64-apple-darwin +cargo build --release --target x86_64-apple-darwin +cargo build --release --target x86_64-unknown-linux-gnu + +mv target/aarch64-apple-darwin/release/yazi target/yazi-aarch64-apple-darwin +mv target/x86_64-apple-darwin/release/yazi target/yazi-x86_64-apple-darwin +mv target/x86_64-unknown-linux-gnu/release/yazi target/yazi-x86_64-unknown-linux-gnu + +zip -j yazi-aarch64-apple-darwin.zip target/yazi-aarch64-apple-darwin +zip -j yazi-x86_64-apple-darwin.zip target/yazi-x86_64-apple-darwin +zip -j yazi-x86_64-unknown-linux-gnu.zip target/yazi-x86_64-unknown-linux-gnu diff --git a/src/config/preset.rs b/src/config/preset.rs index 02b49924..d9e4ac0f 100644 --- a/src/config/preset.rs +++ b/src/config/preset.rs @@ -15,43 +15,41 @@ impl Preset { continue; }; - if k == "icons" { + if k == "icons" || max <= 1 { continue; } - if max - 1 > 0 { + if let Some(a) = a.as_table_mut() { if let Some(b) = v.as_table() { - if let Some(a) = a.as_table_mut() { - Self::merge(a, b, max - 1); - continue; - } + Self::merge(a, b, max - 1); + continue; } } *a = v.clone(); } } - fn merge_str(base: &str, user: &str) -> String { + fn merge_str(user: &str, base: &str) -> String { let path = BaseDirectories::new().unwrap().get_config_file(user); - let user = fs::read_to_string(path).unwrap_or("".to_string()).parse::().unwrap(); + let mut user = fs::read_to_string(path).unwrap_or("".to_string()).parse::
().unwrap(); - let mut base = base.parse::
().unwrap(); - Self::merge(&mut base, &user, 2); - base.to_string() + let base = base.parse::
().unwrap(); + Self::merge(&mut user, &base, 2); + user.to_string() } #[inline] pub(crate) fn keymap() -> String { - Self::merge_str(include_str!("../../config/keymap.toml"), "yazi/keymap.toml") + Self::merge_str("yazi/keymap.toml", include_str!("../../config/keymap.toml")) } #[inline] pub(crate) fn theme() -> String { - Self::merge_str(include_str!("../../config/theme.toml"), "yazi/theme.toml") + Self::merge_str("yazi/theme.toml", include_str!("../../config/theme.toml")) } #[inline] pub(crate) fn yazi() -> String { - Self::merge_str(include_str!("../../config/yazi.toml"), "yazi/yazi.toml") + Self::merge_str("yazi/yazi.toml", include_str!("../../config/yazi.toml")) } } diff --git a/src/core/external/lsar.rs b/src/core/external/lsar.rs index 81aaff28..40ed04f0 100644 --- a/src/core/external/lsar.rs +++ b/src/core/external/lsar.rs @@ -4,7 +4,6 @@ use anyhow::{bail, Result}; use serde::Deserialize; use serde_json::Value; use tokio::process::Command; -use tracing::info; #[derive(Debug)] pub enum LsarAttr { @@ -45,7 +44,6 @@ pub async fn lsar(path: &Path) -> Result> { } let output = String::from_utf8_lossy(&output.stdout); - info!("lsar output: {}", output); let contents = serde_json::from_str::(output.trim())?.contents; let mut files = Vec::with_capacity(contents.len()); diff --git a/src/core/manager/folder.rs b/src/core/manager/folder.rs index 25995ae9..adab0521 100644 --- a/src/core/manager/folder.rs +++ b/src/core/manager/folder.rs @@ -172,11 +172,11 @@ impl Folder { } pub fn paginate(&self) -> &Slice { - let max = self.files.len().saturating_sub(1); + let len = self.files.len(); let limit = Self::limit(); - let start = (self.page * limit).min(max); - let end = (start + limit).min(max); + let start = (self.page * limit).min(len.saturating_sub(1)); + let end = (start + limit).min(len); self.files.get_range(start..end).unwrap() } diff --git a/src/core/manager/tab.rs b/src/core/manager/tab.rs index 963b85ec..e492ee1e 100644 --- a/src/core/manager/tab.rs +++ b/src/core/manager/tab.rs @@ -170,9 +170,11 @@ impl Tab { true } - pub fn back(&mut self) -> bool { todo!() } + // TODO + pub fn back(&mut self) -> bool { false } - pub fn forward(&mut self) -> bool { todo!() } + // TODO + pub fn forward(&mut self) -> bool { false } pub fn search(&mut self, grep: bool) -> bool { if let Some(handle) = self.search.take() { diff --git a/src/core/tasks/file.rs b/src/core/tasks/file.rs index 9f597494..0b99302e 100644 --- a/src/core/tasks/file.rs +++ b/src/core/tasks/file.rs @@ -4,7 +4,6 @@ use anyhow::Result; use futures::{future::BoxFuture, FutureExt}; use tokio::{fs, io::{self, ErrorKind::{AlreadyExists, NotFound}}, sync::mpsc}; use tracing::{info, trace}; -use trash::{macos::{DeleteMethod, TrashContextExtMacos}, TrashContext}; use super::TaskOp; use crate::misc::{calculate_size, copy_with_progress}; @@ -142,6 +141,7 @@ impl File { FileOp::Trash(task) => { #[cfg(target_os = "macos")] { + use trash::{macos::{DeleteMethod, TrashContextExtMacos}, TrashContext}; let mut ctx = TrashContext::default(); ctx.set_delete_method(DeleteMethod::NsFileManager); ctx.delete(&task.target)?; diff --git a/src/core/tasks/tasks.rs b/src/core/tasks/tasks.rs index 6adef091..07ec0a14 100644 --- a/src/core/tasks/tasks.rs +++ b/src/core/tasks/tasks.rs @@ -90,9 +90,14 @@ impl Tasks { running.values().take(Self::limit()).cloned().collect::>() } - pub fn cancel(&self) -> bool { + pub fn cancel(&mut self) -> bool { let id = self.scheduler.running.read().values().skip(self.cursor).next().map(|t| t.id); - id.map(|id| self.scheduler.cancel(id)).unwrap_or(false) + if !id.map(|id| self.scheduler.cancel(id)).unwrap_or(false) { + return false; + } + + self.next(); + true } pub fn file_open(&self, targets: &[(impl AsRef, impl AsRef)]) -> bool { diff --git a/src/misc/fs.rs b/src/misc/fs.rs index 4af8364b..336d771c 100644 --- a/src/misc/fs.rs +++ b/src/misc/fs.rs @@ -101,7 +101,11 @@ pub fn copy_with_progress(from: &Path, to: &Path) -> mpsc::Receiver String { use libc::{S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFSOCK, S_IRGRP, S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR}; + #[cfg(target_os = "macos")] let m = mode as u16; + #[cfg(target_os = "linux")] + let m = mode; + let mut s = String::with_capacity(10); // File type diff --git a/src/ui/status/progress.rs b/src/ui/status/progress.rs index cfab6984..431d2f6c 100644 --- a/src/ui/status/progress.rs +++ b/src/ui/status/progress.rs @@ -24,7 +24,6 @@ impl<'a> Widget for Progress<'a> { format!("{:>3}%, {} left", progress.0, progress.1), THEME.progress.label.get(), )) - .use_unicode(true) .render(area, buf); } }