diff --git a/src/backend/hotcold.rs b/src/backend/hotcold.rs index 16e23d8..94872ac 100644 --- a/src/backend/hotcold.rs +++ b/src/backend/hotcold.rs @@ -73,7 +73,9 @@ impl WriteBackend for HotColdBackend { async fn write_bytes(&self, tpe: FileType, id: &Id, buf: Vec) -> Result<()> { if let Some(be) = &self.hot_be { - be.write_bytes(tpe, id, buf.clone()).await?; + if tpe != FileType::Config { + be.write_bytes(tpe, id, buf.clone()).await?; + } } self.be.write_bytes(tpe, id, buf).await } diff --git a/src/commands/config.rs b/src/commands/config.rs index 14ab687..c68d356 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -2,7 +2,7 @@ use anyhow::{bail, Result}; use bytesize::ByteSize; use clap::Parser; -use crate::backend::DecryptFullBackend; +use crate::backend::{DecryptBackend, DecryptFullBackend, DecryptWriteBackend, WriteBackend}; use crate::repo::ConfigFile; #[derive(Parser)] @@ -13,13 +13,24 @@ pub(super) struct Opts { pub(super) async fn execute( be: &impl DecryptFullBackend, + hot_be: &Option, opts: Opts, config: ConfigFile, ) -> Result<()> { let mut new_config = config.clone(); opts.config_opts.apply(&mut new_config)?; if new_config != config { + new_config.is_hot = None; + // for hot/cold backend, this only saves the config to the cold repo. be.save_file(&new_config).await?; + + if let Some(hot_be) = hot_be { + // save config to hot repo + let dbe = DecryptBackend::new(hot_be, be.key().clone()); + new_config.is_hot = Some(true); + dbe.save_file(&new_config).await?; + } + println!("saved new config"); } else { println!("config is unchanged"); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 40321d8..32ba57d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -175,7 +175,7 @@ pub async fn execute() -> Result<()> { match cmd { Command::Backup(opts) => backup::execute(&dbe, opts, config, command).await?, - Command::Config(opts) => config::execute(&dbe, opts, config).await?, + Command::Config(opts) => config::execute(&dbe, &be_hot, opts, config).await?, Command::Cat(opts) => cat::execute(&dbe, opts).await?, Command::Check(opts) => check::execute(&dbe, &cache, &be_hot, &be, opts).await?, Command::Diff(opts) => diff::execute(&dbe, opts).await?,