Skip to content

Commit 9d6c6e6

Browse files
committed
Configure GPTCommit files for Unix systems
- Create default configuration files for GPTcommit - Set permissions for the configuration files (Unix only) Closes #66
1 parent 8b1c832 commit 9d6c6e6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(crate) fn get_hooks_path() -> Result<PathBuf> {
4343
// create dirs first otherwise canonicalize will fail
4444
fs::create_dir_all(&rel_hooks_path)?;
4545
#[cfg(unix)]
46-
fs::set_permissions(&rel_hooks_path, Permissions::from_mode(0o755))?;
46+
fs::set_permissions(&rel_hooks_path, Permissions::from_mode(0o700))?;
4747
// turn relative path into absolute path
4848
let hooks_path = std::fs::canonicalize(rel_hooks_path)?;
4949
Ok(hooks_path)

src/settings.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::{collections::HashMap, fs, path::PathBuf, str::FromStr};
2+
#[cfg(unix)]
3+
use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
24

35
use config::{
46
builder::DefaultState, Config, ConfigBuilder, ConfigError, Environment, File, Source,
@@ -271,6 +273,8 @@ pub fn get_local_config_path() -> Option<PathBuf> {
271273
.join("gptcommit.toml");
272274
if !config_path.exists() {
273275
fs::write(&config_path, "").ok()?;
276+
#[cfg(unix)]
277+
fs::set_permissions(&config_path, Permissions::from_mode(0o600)).unwrap();
274278
}
275279
return Some(config_path);
276280
}
@@ -287,6 +291,8 @@ pub fn get_user_config_path() -> Option<PathBuf> {
287291
let config_path = config_dir.join("config.toml");
288292
if !config_path.exists() {
289293
fs::write(&config_path, "").ok()?;
294+
#[cfg(unix)]
295+
fs::set_permissions(&config_path, Permissions::from_mode(0o600)).unwrap();
290296
}
291297
return Some(config_path);
292298
}

0 commit comments

Comments
 (0)