From 4b5b01192e402bd3d064fa6d4bcdd455106edd98 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 20 Feb 2019 16:31:25 +0100 Subject: [PATCH] followup: try to be a bit more like systemd-escape Signed-off-by: Thomas Lamprecht --- PVE/API2/Disks/Directory.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm index 645c73c..4c74776 100644 --- a/PVE/API2/Disks/Directory.pm +++ b/PVE/API2/Disks/Directory.pm @@ -88,18 +88,25 @@ my $write_ini = sub { }; sub systemd_escape { - my ($val) = @_; + my ($val, $is_path) = @_; # NOTE: this is not complete, but enough for our needs. normally all # characters which are not alpha-numerical, '.' or '_' would need escaping $val =~ s/\-/\\x2d/g; + if ($is_path) { + $val =~ s/^\///g; + $val =~ s/\/$//g; + } + $val =~ s/\//-/g; + return $val; } sub systemd_unescape { my ($val) = @_; + $val =~ s/-/\//g; $val =~ s/\\x([a-fA-F0-9]{2})/chr(hex($1))/eg; return $val; @@ -225,7 +232,7 @@ __PACKAGE__->register_method ({ my $worker = sub { my $path = "/mnt/pve/$name"; - my $mountunitname = "mnt-pve-".systemd_escape($name).".mount"; + my $mountunitname = systemd_escape($path, 1) . ".mount"; my $mountunitpath = "/etc/systemd/system/$mountunitname"; PVE::Diskmanage::locked_disk_action(sub {