Merge #416: gui creates datadir for fresh install
9dccc273bfe1e9513881b2cfa95a9e0caa3882eb gui creates datadir for fresh install (edouard)
Pull request description:
ACKs for top commit:
darosior:
ACK 9dccc273bfe1e9513881b2cfa95a9e0caa3882eb -- tested with a relative datadir (`--datadir ./test`) and everything worked smoothly.
Tree-SHA512: 19ce785b95d53ba12f83780eb5a9f9fdc5bc00b27385e8859ece029669ae954083234561c607b7a29acc5ab2a9e62f715904144ab618bae4653bf1eba562c8d2
This commit is contained in:
commit
c528338e75
@ -211,10 +211,11 @@ pub fn daemon_check(cfg: liana::config::Config) -> Result<(), Error> {
|
|||||||
|
|
||||||
pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
pub async fn install(ctx: Context) -> Result<PathBuf, Error> {
|
||||||
let mut cfg: liana::config::Config = ctx.extract_daemon_config();
|
let mut cfg: liana::config::Config = ctx.extract_daemon_config();
|
||||||
let data_dir =
|
let data_dir = cfg.data_dir.unwrap();
|
||||||
cfg.data_dir.unwrap().canonicalize().map_err(|e| {
|
|
||||||
Error::Unexpected(format!("Failed to canonicalize datadir path: {}", e))
|
let data_dir = data_dir
|
||||||
})?;
|
.canonicalize()
|
||||||
|
.map_err(|e| Error::Unexpected(format!("Failed to canonicalize datadir path: {}", e)))?;
|
||||||
cfg.data_dir = Some(data_dir.clone());
|
cfg.data_dir = Some(data_dir.clone());
|
||||||
|
|
||||||
daemon_check(cfg.clone())?;
|
daemon_check(cfg.clone())?;
|
||||||
|
|||||||
@ -97,8 +97,12 @@ impl Logger {
|
|||||||
|
|
||||||
pub fn remove_install_log_file(&self, mut datadir: PathBuf) {
|
pub fn remove_install_log_file(&self, mut datadir: PathBuf) {
|
||||||
datadir.push(INSTALLER_LOG_FILE_NAME);
|
datadir.push(INSTALLER_LOG_FILE_NAME);
|
||||||
if let Err(e) = std::fs::remove_file(datadir) {
|
if let Err(e) = std::fs::remove_file(&datadir) {
|
||||||
error!("Failed to remove installer log file: {:#?}", e);
|
error!(
|
||||||
|
"Failed to remove installer log file {} error:{:#?}",
|
||||||
|
datadir.to_string_lossy(),
|
||||||
|
e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -111,6 +111,18 @@ impl Application for GUI {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Config::Install(datadir_path, network) => {
|
Config::Install(datadir_path, network) => {
|
||||||
|
if !datadir_path.exists() {
|
||||||
|
// datadir is created right before launching the installer
|
||||||
|
// so logs can go in <datadir_path>/installer.log
|
||||||
|
if let Err(e) = create_datadir(&datadir_path) {
|
||||||
|
error!("Failed to create datadir: {}", e);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"Created a fresh data directory at {}",
|
||||||
|
&datadir_path.to_string_lossy()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
logger.set_installer_mode(datadir_path.clone(), LevelFilter::INFO);
|
logger.set_installer_mode(datadir_path.clone(), LevelFilter::INFO);
|
||||||
let (install, command) = Installer::new(datadir_path, network);
|
let (install, command) = Installer::new(datadir_path, network);
|
||||||
(
|
(
|
||||||
@ -270,6 +282,25 @@ impl Application for GUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_datadir(datadir_path: &std::path::Path) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
#[cfg(unix)]
|
||||||
|
return {
|
||||||
|
use std::fs::DirBuilder;
|
||||||
|
use std::os::unix::fs::DirBuilderExt;
|
||||||
|
|
||||||
|
let mut builder = DirBuilder::new();
|
||||||
|
builder.mode(0o700).recursive(true).create(datadir_path)?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: permissions on Windows..
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
return {
|
||||||
|
std::fs::create_dir_all(datadir_path)?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub enum Config {
|
pub enum Config {
|
||||||
Run(PathBuf, app::Config, bitcoin::Network),
|
Run(PathBuf, app::Config, bitcoin::Network),
|
||||||
Launcher(PathBuf),
|
Launcher(PathBuf),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user