Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create stored_saving_location if not existing, fallback to saving_location on error #297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,15 @@ impl Settings {
pub fn saving_location(&self) -> PathBuf {
let stored_saving_location: PathBuf = self.0.get("saving-location");

if !stored_saving_location.as_os_str().is_empty() {
return stored_saving_location;
}

let saving_location =
glib::user_special_dir(glib::UserDirectory::Videos).unwrap_or_else(glib::home_dir);

let kooha_saving_location = saving_location.join("Kooha");

if let Err(err) = fs::create_dir_all(&kooha_saving_location) {
tracing::warn!(
"Failed to create dir at `{}`: {:?}",
kooha_saving_location.display(),
err
);
return saving_location;
if !stored_saving_location.as_os_str().is_empty() {
return ensure_location(stored_saving_location);
}

kooha_saving_location
let kooha_saving_location = saving_location.join("Kooha");
ensure_location(kooha_saving_location)
}

pub fn connect_saving_location_changed(
Expand Down Expand Up @@ -150,6 +140,18 @@ impl Settings {
}
}

fn ensure_location(saving_location: PathBuf) -> PathBuf {
if let Err(err) = fs::create_dir_all(&saving_location) {
tracing::warn!(
"Failed to create dir at `{}`: {:?}",
saving_location.display(),
err
);
return glib::user_special_dir(glib::UserDirectory::Videos).unwrap_or_else(glib::home_dir);
}
saving_location
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading