From 91f61e5c4ae91eb21167ad7f649b0223ebcc17a3 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sat, 19 Oct 2024 08:29:22 +0200 Subject: [PATCH] fix: delete active runtime if it's a symlink --- src/file_builders/active_runtime_json.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/file_builders/active_runtime_json.rs b/src/file_builders/active_runtime_json.rs index ce4778a..3f5e73f 100644 --- a/src/file_builders/active_runtime_json.rs +++ b/src/file_builders/active_runtime_json.rs @@ -5,7 +5,10 @@ use crate::{ xdg::XDG, }; use serde::{Deserialize, Serialize}; -use std::path::{Path, PathBuf}; +use std::{ + fs::remove_file, + path::{Path, PathBuf}, +}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ActiveRuntimeInnerRuntime { @@ -63,6 +66,9 @@ pub fn get_current_active_runtime() -> Option { } fn dump_active_runtime_to_path(active_runtime: &ActiveRuntime, path: &Path) -> anyhow::Result<()> { + if path.is_symlink() { + remove_file(path)?; + } let writer = get_writer(path)?; serde_json::to_writer_pretty(writer, active_runtime)?; Ok(())