From 2d8ddb71e19b38a2db577c907b6493e73a29c227 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 12 Jul 2020 17:44:00 +0800 Subject: [PATCH] feat(commit-msg): use set mode replace of chmod command --- scripts/commit-msg.crs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/commit-msg.crs b/scripts/commit-msg.crs index 0b52dad..7f005c3 100755 --- a/scripts/commit-msg.crs +++ b/scripts/commit-msg.crs @@ -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)); });