Skip to content

Commit

Permalink
Data folder configuration in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Feb 25, 2024
1 parent aca6909 commit c89d9db
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
9 changes: 8 additions & 1 deletion core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ impl Core {
let application_events_channel = runtime.application_events().clone();
let wallet = runtime.wallet().clone();

let storage = Storage::default();
#[cfg(not(target_arch = "wasm32"))]
if settings.node.kaspad_daemon_storage_folder_enable {
storage.track_storage_root(Some(settings.node.kaspad_daemon_storage_folder.as_str()));
}

let mut this = Self {
runtime,
is_shutdown_pending: false,
Expand Down Expand Up @@ -193,7 +199,8 @@ impl Core {
callback_map: CallbackMap::default(),
network_pressure: NetworkPressure::default(),
notifications: Notifications::default(),
storage: Storage::default(),
storage,
// daemon_storage_root: Mutex::new(daemon_storage_root),
};

modules.values().for_each(|module| {
Expand Down
13 changes: 13 additions & 0 deletions core/src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ impl Settings {
} else if !Path::new(appdir).exists() {
ui.colored_label(theme_color().error_color, i18n("Data storage folder not found at"));
ui.label(format!("\"{}\"",self.settings.node.kaspad_daemon_storage_folder.trim()));

ui.add_space(4.);
if ui.medium_button(i18n("Create Data Folder")).clicked() {
if let Err(err) = std::fs::create_dir_all(appdir) {
runtime().error(format!("Unable to create data storage folder `{appdir}`: {err}"));
}
}
ui.add_space(4.);

node_settings_error = Some(i18n("Data storage folder not found"));
}
}
Expand Down Expand Up @@ -403,6 +412,10 @@ impl Settings {

core.settings = self.settings.clone();
core.settings.store_sync().unwrap();

let storage_root = core.settings.node.kaspad_daemon_storage_folder_enable.then_some(core.settings.node.kaspad_daemon_storage_folder.as_str());
core.storage.track_storage_root(storage_root);

if restart {
self.runtime.kaspa_service().update_services(&self.settings.node, None);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ impl Settings {
}
}
Err(error) => {
#[allow(clippy::if_same_then_else)]
if matches!(error, workflow_store::error::Error::SerdeJson(..)) {
// TODO - recovery process
log_warning!("Settings::load() error: {}", error);
Expand Down
17 changes: 16 additions & 1 deletion core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,25 @@ impl StorageUpdateOptions {
#[derive(Default, Clone)]
pub struct Storage {
pub folders: Arc<Mutex<Vec<StorageFolder>>>,
pub storage_root: Arc<Mutex<Option<PathBuf>>>,
}

#[cfg(not(target_arch = "wasm32"))]
impl Storage {
pub fn track_storage_root(&self, storage_root: Option<&str>) {
*self.storage_root.lock().unwrap() = storage_root.map(PathBuf::from);
self.update(None);
}

pub fn storage_root(&self) -> PathBuf {
self.storage_root
.lock()
.unwrap()
.clone()
.or_else(|| Some(kaspad_lib::daemon::get_app_dir()))
.unwrap()
}

pub fn update(&self, options: Option<StorageUpdateOptions>) {
let options = options.unwrap_or_default();

Expand All @@ -64,7 +79,7 @@ impl Storage {
}
}

let rusty_kaspa_app_dir = kaspad_lib::daemon::get_app_dir();
let rusty_kaspa_app_dir = self.storage_root();
if !rusty_kaspa_app_dir.exists() {
return;
}
Expand Down

0 comments on commit c89d9db

Please sign in to comment.