fixes in paths + better error reporting
This commit is contained in:
@@ -365,8 +365,12 @@ While the stored info point to:\n{stored_info:#?}"
|
||||
#[error("could not find the upgrade binary at {} while the binary download is disabled", path.display())]
|
||||
NoUpgradeBinaryWithDisabledDownload { path: PathBuf },
|
||||
|
||||
#[error("upgrade '{upgrade_name}' does not have any valid download URLs for the current arch '{arch}'")]
|
||||
NoDownloadUrls { upgrade_name: String, arch: String },
|
||||
#[error("upgrade '{upgrade_name}' does not have any valid download URLs for the current arch '{arch}'. The available arches are: {available:?}")]
|
||||
NoDownloadUrls {
|
||||
upgrade_name: String,
|
||||
arch: String,
|
||||
available: Vec<String>,
|
||||
},
|
||||
|
||||
#[error("failed to download the upgrade binary from '{url}': {source}")]
|
||||
UpgradeDownloadFailure {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
use crate::config::NYMVISOR_DIR;
|
||||
use crate::error::NymvisorError;
|
||||
use crate::helpers::init_path;
|
||||
use flate2::write::GzEncoder;
|
||||
use flate2::Compression;
|
||||
use std::fs;
|
||||
@@ -33,7 +34,11 @@ pub(crate) struct BackupBuilder {
|
||||
|
||||
impl BackupBuilder {
|
||||
pub(crate) fn new<P: AsRef<Path>>(backup_directory: P) -> Result<Self, NymvisorError> {
|
||||
let backup_filepath = backup_directory.as_ref().join(generate_backup_filename());
|
||||
let backup_directory = backup_directory.as_ref();
|
||||
let backup_filepath = backup_directory.join(generate_backup_filename());
|
||||
|
||||
// create the backup directory itself (i.e. specific for this upgrade) if it doesn't yet exist
|
||||
init_path(backup_directory)?;
|
||||
|
||||
// create the backup file
|
||||
let backup_file = fs::File::create(&backup_filepath).map_err(|source| {
|
||||
|
||||
@@ -182,7 +182,6 @@ impl DaemonLauncher {
|
||||
error!("CRITICAL FAILURE: the upgrade plan watcher channel got closed");
|
||||
panic!("CRITICAL FAILURE: the upgrade plan watcher channel got closed")
|
||||
};
|
||||
println!("the file has changed - {event:?}");
|
||||
|
||||
debug!("the file has changed - {event:?}");
|
||||
if let Some(next_upgrade) = self.check_upgrade_plan_changes() {
|
||||
|
||||
@@ -35,6 +35,10 @@ async fn chunk_download(
|
||||
download_url: &DownloadUrl,
|
||||
download_target: &PathBuf,
|
||||
) -> Result<(), NymvisorError> {
|
||||
info!(
|
||||
"attempting to download the binary from '{}'",
|
||||
download_url.url
|
||||
);
|
||||
let response = reqwest::get(download_url.url.clone())
|
||||
.await
|
||||
.map_err(|source| NymvisorError::UpgradeDownloadFailure {
|
||||
|
||||
@@ -48,7 +48,7 @@ pub(crate) async fn perform_upgrade(config: &Config) -> Result<UpgradeResult, Ny
|
||||
let mut upgrade_history = if history_path.exists() {
|
||||
UpgradeHistory::try_load(history_path)?
|
||||
} else {
|
||||
UpgradeHistory::new()
|
||||
UpgradeHistory::new(history_path)
|
||||
};
|
||||
|
||||
debug!("creating the lock file");
|
||||
@@ -77,7 +77,7 @@ pub(crate) async fn perform_upgrade(config: &Config) -> Result<UpgradeResult, Ny
|
||||
});
|
||||
}
|
||||
info!(
|
||||
"upgrade binary not found at {}. attempting to to download it",
|
||||
"upgrade binary not found at '{}'. attempting to to download it",
|
||||
upgrade_binary_path.display()
|
||||
);
|
||||
|
||||
@@ -107,7 +107,7 @@ pub(crate) async fn perform_upgrade(config: &Config) -> Result<UpgradeResult, Ny
|
||||
upgrade_history.insert_new_upgrade(next)?;
|
||||
|
||||
// update the 'current' symlink
|
||||
set_upgrade_link(config, config.upgrade_binary_dir(&upgrade_name))?;
|
||||
set_upgrade_link(config, config.upgrade_dir(&upgrade_name))?;
|
||||
|
||||
// finally remove the lock file
|
||||
fs::remove_file(&lock_path).map_err(|source| NymvisorError::LockFileRemovalFailure {
|
||||
|
||||
@@ -297,6 +297,7 @@ impl UpgradeInfo {
|
||||
.ok_or(NymvisorError::NoDownloadUrls {
|
||||
upgrade_name: self.name.clone(),
|
||||
arch: os_arch(),
|
||||
available: self.platforms.keys().cloned().collect(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -377,9 +378,9 @@ impl UpgradeHistoryEntry {
|
||||
}
|
||||
|
||||
impl UpgradeHistory {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new<P: AsRef<Path>>(save_path: P) -> Self {
|
||||
UpgradeHistory {
|
||||
_save_path: None,
|
||||
_save_path: Some(save_path.as_ref().to_path_buf()),
|
||||
history: vec![],
|
||||
}
|
||||
}
|
||||
@@ -424,7 +425,7 @@ impl UpgradeHistory {
|
||||
|
||||
pub(crate) fn try_load<P: AsRef<Path>>(path: P) -> Result<Self, NymvisorError> {
|
||||
let path = path.as_ref();
|
||||
fs::File::open(path)
|
||||
let mut history: UpgradeHistory = fs::File::open(path)
|
||||
.and_then(|file| {
|
||||
serde_json::from_reader(file)
|
||||
.map_err(|serde_json_err| io::Error::new(io::ErrorKind::Other, serde_json_err))
|
||||
@@ -432,7 +433,10 @@ impl UpgradeHistory {
|
||||
.map_err(|source| NymvisorError::UpgradeHistoryLoadFailure {
|
||||
path: path.to_path_buf(),
|
||||
source,
|
||||
})
|
||||
})?;
|
||||
|
||||
history._save_path = Some(path.to_path_buf());
|
||||
Ok(history)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user