Skip to content

Commit

Permalink
feat(rust): improve the move of a vault file
Browse files Browse the repository at this point in the history
make it more robust to make sure that the path in database always points to an
existing file
  • Loading branch information
etorreborre committed Dec 19, 2023
1 parent e9962ac commit 1a5a0b0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions implementations/rust/ockam/ockam_api/src/cli_state/vaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,14 @@ impl CliState {
if vault.path() == self.database_path() {
return Err(ockam_core::Error::new(Origin::Api, Kind::Invalid, format!("The vault at path {:?} cannot be moved to {path:?} because this is the default vault", vault.path())).into());
};
std::fs::rename(vault.path(), path)?;
Ok(repository.update_vault(vault_name, path).await?)

// copy the file to the new location
std::fs::copy(vault.path(), path)?;
// update the path in the database
repository.update_vault(vault_name, path).await?;
// remove the old file
std::fs::remove_file(vault.path())?;
Ok(())
}
}

Expand Down

0 comments on commit 1a5a0b0

Please sign in to comment.