| 722 | } |
| 723 | |
| 724 | pub fn save(&self) { |
| 725 | let home_path = &self.home_path; |
| 726 | // If the `home_path` is in a directory, ensure it exists. |
| 727 | home_path.create_parent().unwrap(); |
| 728 | |
| 729 | let config = self.doc().to_string(); |
| 730 | |
| 731 | eprintln!("Saving config to {}.", home_path.display()); |
| 732 | // TODO: We currently have a race condition if multiple processes are modifying the config. |
| 733 | // If process X and process Y read the config, each make independent changes, and then save |
| 734 | // the config, the first writer will have its changes clobbered by the second writer. |
| 735 | // |
| 736 | // We used to use `Lockfile` to prevent this from happening, but we had other issues with |
| 737 | // that approach (see https://github.com/clockworklabs/SpacetimeDB/issues/1339, and the |
| 738 | // TODO in `lockfile.rs`). |
| 739 | // |
| 740 | // We should address this issue, but we currently don't expect it to arise very frequently |
| 741 | // (see https://github.com/clockworklabs/SpacetimeDB/pull/1341#issuecomment-2150857432). |
| 742 | if let Err(e) = atomic_write(&home_path.0, config) { |
| 743 | eprintln!("Could not save config file: {e}") |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | pub fn server_decoding_key(&self, server: Option<&str>) -> anyhow::Result<DecodingKey> { |
| 748 | self.server_fingerprint(server).and_then(|fing| { |