From 6a1b3332c522df85aca578fbad4dc18171f57186 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 7 Feb 2024 12:01:30 +0100 Subject: [PATCH] fixed lair-keystore version --- .../src/versions/init.rs | 7 +- .../src/versions/launch.rs | 74 +++++++++++-------- scripts/setup-binaries.sh | 4 +- src/components/settings/About.vue | 2 +- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/crates/lair_keystore_manager/src/versions/init.rs b/crates/lair_keystore_manager/src/versions/init.rs index b6da1450..bc1e9fb6 100644 --- a/crates/lair_keystore_manager/src/versions/init.rs +++ b/crates/lair_keystore_manager/src/versions/init.rs @@ -1,4 +1,7 @@ -use std::{path::{Path, PathBuf}, time::Duration}; +use std::{ + path::{Path, PathBuf}, + time::Duration, +}; use tauri::api::process::{Command, CommandEvent}; @@ -12,7 +15,7 @@ pub fn is_initialized(keystore_path: PathBuf) -> bool { pub async fn initialize(keystore_path: PathBuf, password: String) -> Result<(), LairKeystoreError> { // NEW_VERSION Check whether lair-keystore version needs to get updated - let (mut lair_rx, mut command_child) = Command::new_sidecar("lair-keystore-v0.3.0") + let (mut lair_rx, mut command_child) = Command::new_sidecar("lair-keystore-v0.4.2") .or(Err(LairKeystoreError::LaunchChildError( LaunchChildError::BinaryNotFound, )))? diff --git a/crates/lair_keystore_manager/src/versions/launch.rs b/crates/lair_keystore_manager/src/versions/launch.rs index 5039b9c5..17705277 100644 --- a/crates/lair_keystore_manager/src/versions/launch.rs +++ b/crates/lair_keystore_manager/src/versions/launch.rs @@ -18,7 +18,7 @@ pub async fn launch_lair_keystore_process( // On Unix systems, there is a limit to the path length of a domain socket. Create a symlink to the lair directory from the tempdir // instead and overwrite the connectionUrl in the lair-keystore-config.yaml - if cfg!(target_family="unix") { + if cfg!(target_family = "unix") { let uid = nanoid::nanoid!(13); let src_path = std::env::temp_dir().join(format!("lair.{}", uid)); symlink::symlink_dir(keystore_path, src_path.clone()) @@ -27,11 +27,15 @@ pub async fn launch_lair_keystore_process( // overwrite connectionUrl in lair-keystore-config.yaml to symlink directory // 1. read to string - let mut lair_config_string = std::fs::read_to_string(keystore_path.join("lair-keystore-config.yaml")) - .map_err(|e| LairKeystoreError::ErrorReadingLairConfig(e.to_string()))?; + let mut lair_config_string = + std::fs::read_to_string(keystore_path.join("lair-keystore-config.yaml")) + .map_err(|e| LairKeystoreError::ErrorReadingLairConfig(e.to_string()))?; // 2. filter out the line with the connectionUrl - let connection_url_line = lair_config_string.lines().filter(|line| line.contains("connectionUrl:")).collect::(); + let connection_url_line = lair_config_string + .lines() + .filter(|line| line.contains("connectionUrl:")) + .collect::(); // 3. replace the part unix:///home/[user]/.local/share/holochain-launcher/profiles/default/lair/0.2/socket?k=[some_key] // with unix://[path to tempdir]/socket?k=[some_key] @@ -42,29 +46,37 @@ pub async fn launch_lair_keystore_process( keystore_path.join(socket).to_str().unwrap(), )) { Ok(url) => url, - Err(e) => return Err(LairKeystoreError::OtherError(format!("Failed to parse URL for symlink lair path: {}", e))), + Err(e) => { + return Err(LairKeystoreError::OtherError(format!( + "Failed to parse URL for symlink lair path: {}", + e + ))) + } }; let new_line = &format!("connectionUrl: {}\n", tempdir_connection_url); // 4. Replace the existing connectionUrl line with that new line - lair_config_string = LinesWithEndings::from(lair_config_string.as_str()).map(|line| { - if line.contains("connectionUrl:") { - new_line - } else { - line - } - }).collect::(); + lair_config_string = LinesWithEndings::from(lair_config_string.as_str()) + .map(|line| { + if line.contains("connectionUrl:") { + new_line + } else { + line + } + }) + .collect::(); // 5. Overwrite the lair-keystore-config.yaml with the modified content - std::fs::write(keystore_data_dir.join("lair-keystore-config.yaml"), lair_config_string) - .map_err(|e| LairKeystoreError::ErrorWritingLairConfig(e.to_string()))?; + std::fs::write( + keystore_data_dir.join("lair-keystore-config.yaml"), + lair_config_string, + ) + .map_err(|e| LairKeystoreError::ErrorWritingLairConfig(e.to_string()))?; } - - // NEW_VERSION Check whether lair-keystore version needs to get updated - let (mut lair_rx, mut command_child) = Command::new_sidecar("lair-keystore-v0.3.0") + let (mut lair_rx, mut command_child) = Command::new_sidecar("lair-keystore-v0.4.2") .or(Err(LairKeystoreError::LaunchChildError( LaunchChildError::BinaryNotFound, )))? @@ -118,7 +130,7 @@ pub async fn launch_lair_keystore_process( }); // NEW_VERSION Check whether lair-keystore version needs to get updated - let output = Command::new_sidecar("lair-keystore-v0.3.0") + let output = Command::new_sidecar("lair-keystore-v0.4.2") .or(Err(LairKeystoreError::LaunchChildError( LaunchChildError::BinaryNotFound, )))? @@ -143,8 +155,6 @@ pub async fn launch_lair_keystore_process( Ok(url) } - - /// Iterator yielding every line in a string. The line includes newline character(s). /// https://stackoverflow.com/questions/40455997/iterate-over-lines-in-a-string-including-the-newline-characters pub struct LinesWithEndings<'a> { @@ -153,9 +163,7 @@ pub struct LinesWithEndings<'a> { impl<'a> LinesWithEndings<'a> { pub fn from(input: &'a str) -> LinesWithEndings<'a> { - LinesWithEndings { - input: input, - } + LinesWithEndings { input: input } } } @@ -164,12 +172,16 @@ impl<'a> Iterator for LinesWithEndings<'a> { #[inline] fn next(&mut self) -> Option<&'a str> { - if self.input.is_empty() { - return None; - } - let split = self.input.find('\n').map(|i| i + 1).unwrap_or(self.input.len()); - let (line, rest) = self.input.split_at(split); - self.input = rest; - Some(line) + if self.input.is_empty() { + return None; + } + let split = self + .input + .find('\n') + .map(|i| i + 1) + .unwrap_or(self.input.len()); + let (line, rest) = self.input.split_at(split); + self.input = rest; + Some(line) } -} \ No newline at end of file +} diff --git a/scripts/setup-binaries.sh b/scripts/setup-binaries.sh index f31b9523..971c1a13 100644 --- a/scripts/setup-binaries.sh +++ b/scripts/setup-binaries.sh @@ -1,7 +1,7 @@ #!/bin/bash -REQUIRED_HOLOCHAIN_VERSION="0.2.3" -REQUIRED_LAIR_VERSION="0.3.0" +REQUIRED_HOLOCHAIN_VERSION="0.2.6" +REQUIRED_LAIR_VERSION="0.4.2" # Check that this script is being run from the right location if [ ! -f "package.json" ] || [ ! -f "src-tauri/tauri.conf.json" ]; diff --git a/src/components/settings/About.vue b/src/components/settings/About.vue index fa8cb6a1..2e95c6e3 100644 --- a/src/components/settings/About.vue +++ b/src/components/settings/About.vue @@ -31,7 +31,7 @@ Holochain v{{ version }} - Lair Keystore v0.3.0 + Lair Keystore v0.4.2