]> git.proxmox.com Git - pve-storage.git/commitdiff
new helper abs_filesystem_path()
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 1 Oct 2013 10:26:19 +0000 (12:26 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 1 Oct 2013 10:29:39 +0000 (12:29 +0200)
Returns the absolute path for a <volid>. Also activates storage if possible.

PVE/Storage.pm

index b38990a3ba5e524618310049de1b91c5367c0400..264239695e8fd7fc1930b4aa6487d50c8109305d 100755 (executable)
@@ -372,6 +372,27 @@ sub path {
     return wantarray ? ($path, $owner, $vtype) : $path;
 }
 
+sub abs_filesystem_path {
+    my ($cfg, $volid) = @_;
+
+    my $path;
+    if (PVE::Storage::parse_volume_id ($volid, 1)) {
+       PVE::Storage::activate_volumes($cfg, [ $volid ]);
+       $path = PVE::Storage::path($cfg, $volid);
+    } else {
+       if (-f $volid) {
+           my $abspath = abs_path($volid);
+           if ($abspath && $abspath =~ m|^(/.+)$|) {
+               $path = $1; # untaint any path
+           }
+       }
+    }
+
+    die "can't find file '$volid'\n" if !($path && -f $path);
+
+    return $path;
+}
+
 sub storage_migrate {
     my ($cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;