]> git.proxmox.com Git - pve-storage.git/commitdiff
followup: try to be a bit more like systemd-escape
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 20 Feb 2019 15:31:25 +0000 (16:31 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 20 Feb 2019 15:31:25 +0000 (16:31 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Disks/Directory.pm

index 645c73c09c1c1ed03ae5fd445c4eaa512f01d031..4c74776276874b99684f3be927624d261daf0759 100644 (file)
@@ -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 {