From 385283173bf9cd4679c4696709776dc2ebff6106 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Wed, 8 Mar 2023 13:50:18 -0800 Subject: [PATCH] Only symlink if the link doesn't already exist in configure_init_service.rs (#317) --- src/action/common/configure_init_service.rs | 40 +++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/action/common/configure_init_service.rs b/src/action/common/configure_init_service.rs index aba28d1..489109c 100644 --- a/src/action/common/configure_init_service.rs +++ b/src/action/common/configure_init_service.rs @@ -210,26 +210,30 @@ impl Action for ConfigureInitService { // cli, interactively ask for permission to remove the file Self::check_if_systemd_unit_exists(SERVICE_SRC, SERVICE_DEST).await?; - tokio::fs::symlink(SERVICE_SRC, SERVICE_DEST) - .await - .map_err(|e| { - ActionError::Symlink( - PathBuf::from(SERVICE_SRC), - PathBuf::from(SERVICE_DEST), - e, - ) - })?; + if !Path::new(SERVICE_DEST).exists() { + tokio::fs::symlink(SERVICE_SRC, SERVICE_DEST) + .await + .map_err(|e| { + ActionError::Symlink( + PathBuf::from(SERVICE_SRC), + PathBuf::from(SERVICE_DEST), + e, + ) + })?; + } Self::check_if_systemd_unit_exists(SOCKET_SRC, SOCKET_DEST).await?; - tokio::fs::symlink(SOCKET_SRC, SOCKET_DEST) - .await - .map_err(|e| { - ActionError::Symlink( - PathBuf::from(SOCKET_SRC), - PathBuf::from(SOCKET_DEST), - e, - ) - })?; + if !Path::new(SOCKET_DEST).exists() { + tokio::fs::symlink(SOCKET_SRC, SOCKET_DEST) + .await + .map_err(|e| { + ActionError::Symlink( + PathBuf::from(SOCKET_SRC), + PathBuf::from(SOCKET_DEST), + e, + ) + })?; + } if *start_daemon { execute_command(