Support legacy data directories (#2846)

This commit is contained in:
Paul Hauner
2021-12-02 08:44:38 +11:00
parent ab86b42874
commit 94385fe17b
3 changed files with 91 additions and 2 deletions

View File

@@ -141,11 +141,47 @@ impl Config {
ensure_dir_exists(self.get_freezer_db_path())
}
/// Returns the "modern" path to the data_dir.
///
/// See `Self::get_data_dir` documentation for more info.
fn get_modern_data_dir(&self) -> PathBuf {
self.data_dir.clone()
}
/// Returns the "legacy" path to the data_dir.
///
/// See `Self::get_data_dir` documentation for more info.
pub fn get_existing_legacy_data_dir(&self) -> Option<PathBuf> {
dirs::home_dir()
.map(|home_dir| home_dir.join(&self.data_dir))
// Return `None` if the directory does not exists.
.filter(|dir| dir.exists())
// Return `None` if the legacy directory is identical to the modern.
.filter(|dir| *dir != self.get_modern_data_dir())
}
/// Returns the core path for the client.
///
/// Will not create any directories.
pub fn get_data_dir(&self) -> PathBuf {
self.data_dir.clone()
///
/// ## Legacy Info
///
/// Legacy versions of Lighthouse did not properly handle relative paths for `--datadir`.
///
/// For backwards compatibility, we still compute the legacy path and check if it exists. If
/// it does exist, we use that directory rather than the modern path.
///
/// For more information, see:
///
/// https://github.com/sigp/lighthouse/pull/2843
fn get_data_dir(&self) -> PathBuf {
let existing_legacy_dir = self.get_existing_legacy_data_dir();
if let Some(legacy_dir) = existing_legacy_dir {
legacy_dir
} else {
self.get_modern_data_dir()
}
}
/// Returns the core path for the client.

View File

@@ -66,6 +66,15 @@ impl<E: EthSpec> ProductionBeaconNode<E> {
let freezer_db_path = client_config.create_freezer_db_path()?;
let executor = context.executor.clone();
if let Some(legacy_dir) = client_config.get_existing_legacy_data_dir() {
warn!(
log,
"Legacy datadir location";
"msg" => "this occurs when using relative paths for a datadir location",
"location" => ?legacy_dir,
)
}
if !client_config.chain.enable_lock_timeouts {
info!(log, "Disabling lock timeouts globally");
TimeoutRwLock::disable_timeouts()