Skip to content

Commit

Permalink
Issue buckyos#196: ood-installer can control system-config.toml overw…
Browse files Browse the repository at this point in the history
…rite with --overwrite
  • Loading branch information
weiqiushi authored and streetycat committed May 12, 2023
1 parent 62de0a0 commit 2874790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/tools/ood-installer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async fn main_run() {
}

let config_gen = SystemConfigGen::new(&target);
if let Err(_e) = config_gen.gen() {
if let Err(_e) = config_gen.gen(matches.is_present("overwrite")) {
std::process::exit(-1);
}
// 初始化system_config+device_config,sync-repo和初始化ood-daemon需要依赖此操作
Expand Down
15 changes: 10 additions & 5 deletions src/tools/ood-installer/src/system_config_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl SystemConfigGen {
}
}

pub fn gen(&self) -> BuckyResult<()> {
pub fn gen(&self, overwrite: bool) -> BuckyResult<()> {
let platform_target = Self::get_platform();

// 如果是solo模式,那么config也使用本地配置
Expand All @@ -50,14 +50,14 @@ impl SystemConfigGen {

info!("system-config.toml as follows:\n{}", value);

return Self::save(value);
return Self::save(value, overwrite);
}

fn get_platform() -> &'static str {
cyfs_base::get_target()
}

fn save(value: String) -> BuckyResult<()> {
fn save(value: String, overwrite: bool) -> BuckyResult<()> {
let root = ::cyfs_util::get_cyfs_root_path()
.join("etc")
.join("ood-daemon");
Expand All @@ -75,9 +75,14 @@ impl SystemConfigGen {
let config_file_path = root.join("system-config.toml");
if config_file_path.exists() {
warn!(
"{} already exists! now will overwrite.",
config_file_path.display()
"{} already exists! now will {}.",
config_file_path.display(),
if overwrite {"overwrite"} else {"skip save"}
);
if !overwrite {
return Ok(());
}

}

if let Err(e) = std::fs::write(&config_file_path, value.as_bytes()) {
Expand Down

0 comments on commit 2874790

Please sign in to comment.