Skip to content

Commit

Permalink
fix: specify each target os (momentohq#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
poppoerika authored Apr 18, 2022
1 parent 66daa07 commit 2c44e66
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/commands/configure/configure_cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use log::info;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use tokio::fs;

Expand Down Expand Up @@ -138,7 +137,51 @@ async fn prompt_user_for_config(quick: bool, profile_name: &str) -> Result<Confi
})
}

#[cfg(target_os = "linux")]
async fn set_file_read_write(path: &str) -> Result<(), CliError> {
use std::os::unix::fs::PermissionsExt;
let mut perms = match fs::metadata(path).await {
Ok(p) => p,
Err(e) => {
return Err(CliError {
msg: format!("failed to get file permissions {}", e),
})
}
}
.permissions();
perms.set_mode(0o600);
match fs::set_permissions(path, perms).await {
Ok(_) => Ok(()),
Err(e) => Err(CliError {
msg: format!("failed to set file permissions {}", e),
}),
}
}

#[cfg(target_os = "macos")]
async fn set_file_read_write(path: &str) -> Result<(), CliError> {
use std::os::unix::fs::PermissionsExt;
let mut perms = match fs::metadata(path).await {
Ok(p) => p,
Err(e) => {
return Err(CliError {
msg: format!("failed to get file permissions {}", e),
})
}
}
.permissions();
perms.set_mode(0o600);
match fs::set_permissions(path, perms).await {
Ok(_) => Ok(()),
Err(e) => Err(CliError {
msg: format!("failed to set file permissions {}", e),
}),
}
}

#[cfg(target_os = "ubuntu")]
async fn set_file_read_write(path: &str) -> Result<(), CliError> {
use std::os::unix::fs::PermissionsExt;
let mut perms = match fs::metadata(path).await {
Ok(p) => p,
Err(e) => {
Expand Down

0 comments on commit 2c44e66

Please sign in to comment.