[pbs-devel] [PATCH proxmox-backup 1/2] api: disks: directory: factor out helper for mount unit path

Shannon Sterz s.sterz at proxmox.com
Wed Nov 27 16:21:39 CET 2024


On Wed Nov 27, 2024 at 4:06 PM CET, Fiona Ebner wrote:
> In preparation to check for a pre-existing mount unit.
>
> Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
> ---
>  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..7bdf0111 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),

nit, this could be:

```rs
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<String, Error> {
> -    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!(

other than that consider this:

Reviewed-by: Shannon Sterz <s.sterz at proxmox.com>






More information about the pbs-devel mailing list