diff options
| -rw-r--r-- | Cargo.lock | 10 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/lib.rs | 16 |
3 files changed, 20 insertions, 7 deletions
@@ -439,6 +439,7 @@ dependencies = [ "happylock", "hostname", "inquire", + "is_executable", "log", "notify", "notify-debouncer-full", @@ -693,6 +694,15 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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" @@ -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<String, git2::Error> { 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<i32> { + 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<Oid, TreeError> { @@ -160,7 +162,7 @@ pub fn path_to_tree(repository: &Repository, path: &Path) -> Result<Oid, TreeErr continue; } - let filemode = filemode_for_dir_entry(&entry.metadata()?); + let filemode = filemode_for_dir_entry(&entry.path())?; let oid = path_to_tree(repository, &entry.path())?; let filename = entry.file_name(); tree.insert(filename, oid, filemode)?; |
