Respect system paths.
This commit is contained in:
parent
801596395e
commit
4410fb635a
@ -34,7 +34,7 @@ use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_pri
|
||||
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
|
||||
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
|
||||
use ethcore_logger::Config as LogConfig;
|
||||
use dir::Directories;
|
||||
use dir::{Directories, default_hypervisor_path};
|
||||
use dapps::Configuration as DappsConfiguration;
|
||||
use signer::{Configuration as SignerConfiguration};
|
||||
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
|
||||
@ -701,6 +701,7 @@ impl Configuration {
|
||||
"current" => ReleaseTrack::Unknown,
|
||||
_ => return Err("Invalid value for `--releases-track`. See `--help` for more information.".into()),
|
||||
},
|
||||
path: default_hypervisor_path(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -810,7 +811,7 @@ mod tests {
|
||||
use ethcore::miner::{MinerOptions, PrioritizationStrategy};
|
||||
use helpers::{default_network_config};
|
||||
use run::RunCmd;
|
||||
use dir::Directories;
|
||||
use dir::{Directories, default_hypervisor_path};
|
||||
use signer::{Configuration as SignerConfiguration};
|
||||
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat, ExportState};
|
||||
use presale::ImportWallet;
|
||||
@ -1011,7 +1012,7 @@ mod tests {
|
||||
acc_conf: Default::default(),
|
||||
gas_pricer: Default::default(),
|
||||
miner_extras: Default::default(),
|
||||
update_policy: UpdatePolicy { enable_downloading: true, require_consensus: true, filter: UpdateFilter::Critical, track: ReleaseTrack::Unknown },
|
||||
update_policy: UpdatePolicy { enable_downloading: true, require_consensus: true, filter: UpdateFilter::Critical, track: ReleaseTrack::Unknown, path: default_hypervisor_path() },
|
||||
mode: Default::default(),
|
||||
tracing: Default::default(),
|
||||
compaction: Default::default(),
|
||||
@ -1064,9 +1065,9 @@ mod tests {
|
||||
let conf3 = parse(&["parity", "--auto-update=xxx"]);
|
||||
|
||||
// then
|
||||
assert_eq!(conf0.update_policy().unwrap(), UpdatePolicy{enable_downloading: true, require_consensus: true, filter: UpdateFilter::Critical, track: ReleaseTrack::Testing});
|
||||
assert_eq!(conf1.update_policy().unwrap(), UpdatePolicy{enable_downloading: true, require_consensus: false, filter: UpdateFilter::All, track: ReleaseTrack::Unknown});
|
||||
assert_eq!(conf2.update_policy().unwrap(), UpdatePolicy{enable_downloading: false, require_consensus: true, filter: UpdateFilter::All, track: ReleaseTrack::Beta});
|
||||
assert_eq!(conf0.update_policy().unwrap(), UpdatePolicy{enable_downloading: true, require_consensus: true, filter: UpdateFilter::Critical, track: ReleaseTrack::Testing, path: default_hypervisor_path()});
|
||||
assert_eq!(conf1.update_policy().unwrap(), UpdatePolicy{enable_downloading: true, require_consensus: false, filter: UpdateFilter::All, track: ReleaseTrack::Unknown, path: default_hypervisor_path()});
|
||||
assert_eq!(conf2.update_policy().unwrap(), UpdatePolicy{enable_downloading: false, require_consensus: true, filter: UpdateFilter::All, track: ReleaseTrack::Beta, path: default_hypervisor_path()});
|
||||
assert!(conf3.update_policy().is_err());
|
||||
}
|
||||
|
||||
|
@ -195,6 +195,11 @@ pub fn default_data_path() -> String {
|
||||
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
|
||||
}
|
||||
|
||||
pub fn default_hypervisor_path() -> String {
|
||||
let app_info = AppInfo { name: "parity-hypervisor", author: "parity" };
|
||||
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity-hypervisor".to_owned())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Directories;
|
||||
|
@ -126,6 +126,7 @@ use cli::Args;
|
||||
use configuration::{Cmd, Execute, Configuration};
|
||||
use deprecated::find_deprecated;
|
||||
use ethcore_logger::setup_log;
|
||||
use dir::default_hypervisor_path;
|
||||
|
||||
fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
|
||||
if let Some(file) = maybe_file {
|
||||
@ -193,10 +194,8 @@ fn sync_main(alt_mains: &mut HashMap<String, fn()>) {
|
||||
alt_mains.insert("sync".to_owned(), sync::main);
|
||||
}
|
||||
|
||||
// TODO: merge with version in Updater.
|
||||
fn updates_path(name: &str) -> PathBuf {
|
||||
let mut dest = PathBuf::from(env::home_dir().unwrap().to_str().expect("env filesystem paths really should be valid; qed"));
|
||||
dest.push(".parity-updates");
|
||||
let mut dest = PathBuf::from(default_hypervisor_path());
|
||||
dest.push(name);
|
||||
dest
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::{fs, env};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::{PathBuf};
|
||||
use util::misc::platform;
|
||||
@ -49,6 +49,8 @@ pub struct UpdatePolicy {
|
||||
pub filter: UpdateFilter,
|
||||
/// Which track we should be following.
|
||||
pub track: ReleaseTrack,
|
||||
/// Path for the updates to go.
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
impl Default for UpdatePolicy {
|
||||
@ -58,6 +60,7 @@ impl Default for UpdatePolicy {
|
||||
require_consensus: true,
|
||||
filter: UpdateFilter::None,
|
||||
track: ReleaseTrack::Unknown,
|
||||
path: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,9 +178,8 @@ impl Updater {
|
||||
format!("parity-{}.{}.{}-{:?}", v.version.major, v.version.minor, v.version.patch, v.hash)
|
||||
}
|
||||
|
||||
fn updates_path(name: &str) -> PathBuf {
|
||||
let mut dest = PathBuf::from(env::home_dir().unwrap().to_str().expect("env filesystem paths really should be valid; qed"));
|
||||
dest.push(".parity-updates");
|
||||
fn updates_path(&self, name: &str) -> PathBuf {
|
||||
let mut dest = PathBuf::from(self.update_policy.path.clone());
|
||||
dest.push(name);
|
||||
dest
|
||||
}
|
||||
@ -189,7 +191,7 @@ impl Updater {
|
||||
let fetched = s.fetching.take().unwrap();
|
||||
let b = result.map_err(|e| format!("Unable to fetch update ({}): {:?}", fetched.version, e))?;
|
||||
info!(target: "updater", "Fetched latest version ({}) OK to {}", fetched.version, b.display());
|
||||
let dest = Self::updates_path(&Self::update_file_name(&fetched.version));
|
||||
let dest = self.updates_path(&Self::update_file_name(&fetched.version));
|
||||
fs::create_dir_all(dest.parent().expect("at least one thing pushed; qed")).map_err(|e| format!("Unable to create updates path: {:?}", e))?;
|
||||
fs::copy(&b, &dest).map_err(|e| format!("Unable to copy update: {:?}", e))?;
|
||||
info!(target: "updater", "Copied file to {}", dest.display());
|
||||
@ -322,7 +324,7 @@ impl Service for Updater {
|
||||
let mut s = self.state.lock();
|
||||
if let Some(r) = s.ready.take() {
|
||||
let p = Self::update_file_name(&r.version);
|
||||
let n = Self::updates_path("latest");
|
||||
let n = self.updates_path("latest");
|
||||
// TODO: creating then writing is a bit fragile. would be nice to make it atomic.
|
||||
match fs::File::create(&n).and_then(|mut f| f.write_all(p.as_bytes())) {
|
||||
Ok(_) => {
|
||||
|
Loading…
Reference in New Issue
Block a user