Avoid using $HOME if not necessary (#9273)
* Avoid using $HOME if not necessary * Fix concerns and issues
This commit is contained in:
committed by
Niklas Adolfsson
parent
0cfc6bf2a6
commit
25604dc577
@@ -261,7 +261,7 @@ pub fn execute_upgrades(
|
||||
|
||||
upgrade_data_paths(base_path, dirs, pruning);
|
||||
|
||||
match upgrade(Some(&dirs.path)) {
|
||||
match upgrade(&dirs.path) {
|
||||
Ok(upgrades_applied) if upgrades_applied > 0 => {
|
||||
debug!("Executed {} upgrade scripts - ok", upgrades_applied);
|
||||
},
|
||||
|
||||
@@ -102,14 +102,10 @@ fn upgrade_from_version(previous_version: &Version) -> Result<usize, Error> {
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
fn with_locked_version<F>(db_path: Option<&str>, script: F) -> Result<usize, Error>
|
||||
fn with_locked_version<F>(db_path: &str, script: F) -> Result<usize, Error>
|
||||
where F: Fn(&Version) -> Result<usize, Error>
|
||||
{
|
||||
let mut path = db_path.map_or({
|
||||
let mut path = env::home_dir().expect("Applications should have a home dir");
|
||||
path.push(".parity");
|
||||
path
|
||||
}, PathBuf::from);
|
||||
let mut path = PathBuf::from(db_path);
|
||||
create_dir_all(&path).map_err(|_| Error::CannotCreateConfigPath)?;
|
||||
path.push("ver.lock");
|
||||
|
||||
@@ -131,7 +127,7 @@ fn with_locked_version<F>(db_path: Option<&str>, script: F) -> Result<usize, Err
|
||||
result
|
||||
}
|
||||
|
||||
pub fn upgrade(db_path: Option<&str>) -> Result<usize, Error> {
|
||||
pub fn upgrade(db_path: &str) -> Result<usize, Error> {
|
||||
with_locked_version(db_path, |ver| {
|
||||
upgrade_from_version(ver)
|
||||
})
|
||||
@@ -205,6 +201,10 @@ fn upgrade_user_defaults(dirs: &DatabaseDirectories) {
|
||||
}
|
||||
|
||||
pub fn upgrade_data_paths(base_path: &str, dirs: &DatabaseDirectories, pruning: Algorithm) {
|
||||
if env::home_dir().is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let legacy_root_path = replace_home("", "$HOME/.parity");
|
||||
let default_path = default_data_path();
|
||||
if legacy_root_path != base_path && base_path == default_path {
|
||||
|
||||
Reference in New Issue
Block a user