From a7792e16c5cf7bfb7a377ae61d78f433087aeaa9 Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Wed, 27 Nov 2024 17:06:36 +0100 Subject: [PATCH] api: disks: directory: factor out helper for mount unit path In preparation to check for a pre-existing mount unit. Signed-off-by: Fiona Ebner Reviewed-by: Shannon Sterz --- src/api2/node/disks/directory.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index 6a76dd5a..57add02b 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -324,16 +324,23 @@ pub const ROUTER: Router = Router::new() .post(&API_METHOD_CREATE_DATASTORE_DISK) .match_all("name", &ITEM_ROUTER); +fn datastore_mount_unit_path_info(mount_point: &str) -> (String, String) { + let mut mount_unit_name = proxmox_systemd::escape_unit(mount_point, true); + mount_unit_name.push_str(".mount"); + + ( + format!("/etc/systemd/system/{mount_unit_name}"), + mount_unit_name, + ) +} + fn create_datastore_mount_unit( datastore_name: &str, mount_point: &str, fs_type: FileSystemType, what: &str, ) -> Result { - let mut mount_unit_name = proxmox_systemd::escape_unit(mount_point, true); - mount_unit_name.push_str(".mount"); - - let mount_unit_path = format!("/etc/systemd/system/{}", mount_unit_name); + let (mount_unit_path, mount_unit_name) = datastore_mount_unit_path_info(mount_point); let unit = SystemdUnitSection { Description: format!(