feat: support using symlinks to share profiles across devices (#423)

This commit is contained in:
thomasvs authored and GitHub committed 2026-10-04 15:46:31 +01:00
1 parent a4cfec6c73
commit f10df5da0a
2 files changed
+10 -9

No files matched your search

+7 -6
View File
@@ -92,12 +92,13 @@ where
/// Save the relevant Store as a file
pub fn save(&self) -> Result<(), anyhow::Error> {
fs::create_dir_all(self.path.parent().unwrap())?;
let target_path = fs::canonicalize(&self.path).unwrap_or_else(|_| self.path.clone());
fs::create_dir_all(target_path.parent().unwrap())?;
let contents = serde_json::to_string_pretty(&T::into_value(&self.value)?)?;
let temp_path = self.path.with_extension("json.temp");
let backup_path = self.path.with_extension("json.bak");
let temp_path = target_path.with_extension("json.temp");
let backup_path = target_path.with_extension("json.bak");
// Write to temporary file
let mut temp_file = fs::OpenOptions::new().write(true).truncate(true).create(true).open(&temp_path)?;
@@ -108,12 +109,12 @@ where
drop(temp_file);
// If main file exists, back it up
if self.path.exists() {
fs::rename(&self.path, &backup_path)?;
if target_path.exists() {
fs::rename(&target_path, &backup_path)?;
}
// Rename temp file to main file
fs::rename(&temp_path, &self.path)?;
fs::rename(&temp_path, &target_path)?;
// Remove backup file if everything succeeded
if backup_path.exists() {
+3 -3
View File
@@ -243,7 +243,7 @@ pub fn get_device_profiles(device: &str) -> Result<Vec<String>, anyhow::Error> {
let entries = fs::read_dir(device_path)?;
for entry in entries.flatten() {
if entry.metadata()?.is_file() {
if entry.path().is_file() {
let mut id = entry.file_name().to_string_lossy().into_owned();
if id.ends_with(".json") {
id.truncate(id.len() - 5);
@@ -255,10 +255,10 @@ pub fn get_device_profiles(device: &str) -> Result<Vec<String>, anyhow::Error> {
continue;
}
profiles.push(id);
} else if entry.metadata()?.is_dir() {
} else if entry.path().is_dir() {
let entries = fs::read_dir(entry.path())?;
for subentry in entries.flatten() {
if subentry.metadata()?.is_file() {
if subentry.path().is_file() {
let mut id = format!("{}/{}", entry.file_name().to_string_lossy(), subentry.file_name().to_string_lossy());
if id.ends_with(".json") {
id.truncate(id.len() - 5);