Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion mm2src/adex_cli/src/adex_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};

use crate::adex_proc::SmartFractPrecision;
use crate::helpers::rewrite_json_file;
#[cfg(unix)] use crate::helpers::set_file_permissions;
use crate::logging::{error_anyhow, warn_bail};

const PROJECT_QUALIFIER: &str = "com";
Expand All @@ -22,6 +23,8 @@ const VOLUME_PRECISION_MIN: usize = 2;
const VOLUME_PRECISION_MAX: usize = 5;
const VOLUME_PRECISION: SmartFractPrecision = (VOLUME_PRECISION_MIN, VOLUME_PRECISION_MAX);
const PRICE_PRECISION: SmartFractPrecision = (PRICE_PRECISION_MIN, PRICE_PRECISION_MAX);
#[cfg(unix)]
const CFG_FILE_PERM_MODE: u32 = 0o660;

pub(super) fn get_config() {
let Ok(adex_cfg) = AdexConfigImpl::from_config_path() else { return; };
Expand Down Expand Up @@ -151,7 +154,12 @@ impl AdexConfigImpl {
let adex_path_str = cfg_path
.to_str()
.ok_or_else(|| error_anyhow!("Failed to get cfg_path as str"))?;
rewrite_json_file(self, adex_path_str)
rewrite_json_file(self, adex_path_str)?;
#[cfg(unix)]
{
set_file_permissions(adex_path_str, CFG_FILE_PERM_MODE)?;
}
Ok(())
}

fn set_rpc_password(&mut self, rpc_password: String) { self.rpc_password.replace(rpc_password); }
Expand Down
10 changes: 10 additions & 0 deletions mm2src/adex_cli/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
use std::fs;
use std::io::Write;
use std::ops::Deref;
#[cfg(unix)] use std::os::unix::fs::PermissionsExt;
use std::path::Path;

use crate::error_anyhow;
Expand All @@ -22,6 +23,15 @@ where
writer
.write(&data)
.map_err(|error| error_anyhow!("Failed to write data into {file}: {error}"))?;

Ok(())
}

#[cfg(unix)]
pub(crate) fn set_file_permissions(file: &str, unix_mode: u32) -> Result<()> {
let mut perms = fs::metadata(file)?.permissions();
perms.set_mode(unix_mode);
fs::set_permissions(file, perms)?;
Ok(())
}

Expand Down