mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-30 01:53:01 +00:00
linux-rust: handle disconnections and fix rename
This commit is contained in:
@@ -15,18 +15,40 @@ pub fn get_devices_path() -> PathBuf {
|
||||
|
||||
pub fn get_preferences_path() -> PathBuf {
|
||||
let config_dir = std::env::var("XDG_CONFIG_HOME")
|
||||
.unwrap_or_else(|_| format!("{}/.local/share", std::env::var("HOME").unwrap_or_default()));
|
||||
.unwrap_or_else(|_| format!("{}/.config", std::env::var("HOME").unwrap_or_default()));
|
||||
PathBuf::from(config_dir)
|
||||
.join("librepods")
|
||||
.join("preferences.json")
|
||||
}
|
||||
|
||||
pub fn get_app_settings_path() -> PathBuf {
|
||||
let home = std::env::var("HOME").unwrap_or_default();
|
||||
|
||||
let config_dir = std::env::var("XDG_CONFIG_HOME")
|
||||
.unwrap_or_else(|_| format!("{}/.local/share", std::env::var("HOME").unwrap_or_default()));
|
||||
PathBuf::from(config_dir)
|
||||
.unwrap_or_else(|_| format!("{}/.config", home));
|
||||
|
||||
let data_dir = std::env::var("XDG_DATA_HOME")
|
||||
.unwrap_or_else(|_| format!("{}/.local/share", home));
|
||||
|
||||
let new_path = PathBuf::from(&config_dir)
|
||||
.join("librepods")
|
||||
.join("app_settings.json")
|
||||
.join("app_settings.json");
|
||||
|
||||
let old_path = PathBuf::from(&data_dir)
|
||||
.join("app_settings.json");
|
||||
|
||||
// migrate if needed
|
||||
if old_path.exists() && !new_path.exists() {
|
||||
if let Some(parent) = new_path.parent() {
|
||||
let _ = std::fs::create_dir_all(parent);
|
||||
}
|
||||
|
||||
if std::fs::copy(&old_path, &new_path).is_ok() {
|
||||
let _ = std::fs::remove_file(&old_path);
|
||||
}
|
||||
}
|
||||
|
||||
new_path
|
||||
}
|
||||
|
||||
fn e(key: &[u8; 16], data: &[u8; 16]) -> [u8; 16] {
|
||||
|
||||
Reference in New Issue
Block a user