From da6cb19c293c4998a5d8152b3660dc5e8d3b26e0 Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 30 Mar 2026 20:42:35 -0400 Subject: Add check for executability --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/lib.rs | 16 +++++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7553132..fee88d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -439,6 +439,7 @@ dependencies = [ "happylock", "hostname", "inquire", + "is_executable", "log", "notify", "notify-debouncer-full", @@ -692,6 +693,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "is_executable" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baabb8b4867b26294d818bf3f651a454b6901431711abb96e296245888d6e8c4" +dependencies = [ + "windows-sys 0.60.2", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" diff --git a/Cargo.toml b/Cargo.toml index c047e85..4bf7bdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ anyhow = "1" notify = "8" notify-debouncer-full = "0.7" confy = "2" +is_executable = "1" happylock = "0.5" chrono = "0.4" log = "0.4" diff --git a/src/lib.rs b/src/lib.rs index 5a6b7df..0eeee6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ use git2::{ Commit, FetchOptions, MergeOptions, Oid, PushOptions, Reference, RemoteCallbacks, Repository, Signature, Time, Tree, }; +use is_executable::is_executable; use serde::{Deserialize, Serialize}; use thiserror::Error; use uuid::Uuid; @@ -136,16 +137,17 @@ pub fn current_branch(repository: &Repository) -> Result { Ok(branch_name) } -pub fn filemode_for_dir_entry(metadata: &Metadata) -> i32 { - if metadata.is_dir() { +pub fn filemode_for_dir_entry(path: &Path) -> std::io::Result { + let metadata = path.metadata()?; + Ok(if metadata.is_dir() { 0o040000 } else if metadata.is_symlink() { 0o120000 - } else if metadata.permissions().readonly() { - 0o100644 - } else { + } else if is_executable(path) { 0o100755 - } + } else { + 0o100644 + }) } pub fn path_to_tree(repository: &Repository, path: &Path) -> Result { @@ -160,7 +162,7 @@ pub fn path_to_tree(repository: &Repository, path: &Path) -> Result