Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthme committed Feb 7, 2024
2 parents 0a4601c + 6a1b333 commit 9538e1f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
7 changes: 5 additions & 2 deletions crates/lair_keystore_manager/src/versions/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::{Path, PathBuf}, time::Duration};
use std::{
path::{Path, PathBuf},
time::Duration,
};

use tauri::api::process::{Command, CommandEvent};

Expand All @@ -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,
)))?
Expand Down
74 changes: 43 additions & 31 deletions crates/lair_keystore_manager/src/versions/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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::<String>();
let connection_url_line = lair_config_string
.lines()
.filter(|line| line.contains("connectionUrl:"))
.collect::<String>();

// 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]
Expand All @@ -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::<String>();
lair_config_string = LinesWithEndings::from(lair_config_string.as_str())
.map(|line| {
if line.contains("connectionUrl:") {
new_line
} else {
line
}
})
.collect::<String>();

// 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,
)))?
Expand Down Expand Up @@ -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,
)))?
Expand All @@ -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> {
Expand All @@ -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 }
}
}

Expand All @@ -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)
}
}
}
4 changes: 2 additions & 2 deletions scripts/setup-binaries.sh
Original file line number Diff line number Diff line change
@@ -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" ];
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Holochain v{{ version }}
</span>
<!-- NEW_VERSION update lair-keystore version here if required -->
<span style="margin-top: 8px"> Lair Keystore v0.3.0 </span>
<span style="margin-top: 8px"> Lair Keystore v0.4.2 </span>
</div>
</div>
</HCDialogHeaded>
Expand Down

0 comments on commit 9538e1f

Please sign in to comment.