feat(commit-msg): use set mode replace of chmod command

This commit is contained in:
2020-07-12 17:44:00 +08:00
parent c8fa72fca8
commit 2d8ddb71e1

View File

@@ -3,6 +3,7 @@
use std::{ env, fs, process };
use std::path::PathBuf;
use std::process::Command;
use std::os::unix::fs::PermissionsExt;
/// Git commit message format check util
///
@@ -101,14 +102,14 @@ fn install_commit_msg(force: bool) {
exit_with_error_message(&format!("File {:?} exists! or try forceinstall.", git_hooks_commit_msg));
}
print_info(&format!("Copy file: {:?} to : {:?}", commig_msg_exec_file, git_hooks_commit_msg));
print_info(&format!("Copy file: {:?} to: {:?}", commig_msg_exec_file, git_hooks_commit_msg));
let commig_msg_exec_file_content = fs::read(&commig_msg_exec_file).unwrap_or_else(|e| {
exit_with_error_message(&format!("Read file: {:?} failed: {}.", commig_msg_exec_file, e));
});
fs::write(&git_hooks_commit_msg, commig_msg_exec_file_content).unwrap_or_else(|e| {
exit_with_error_message(&format!("Write file: {:?} failed: {}.", git_hooks_commit_msg, e));
});
Command::new("chmod").args(&["+x", git_hooks_commit_msg.to_str().unwrap()]).output().unwrap_or_else(|e| {
fs::set_permissions(&git_hooks_commit_msg, PermissionsExt::from_mode(0o755)).unwrap_or_else(|e| {
exit_with_error_message(&format!("Apply executable permission on file: {:?} failed: {}.", git_hooks_commit_msg, e));
});