From 35fbb2e64595521a081fcfa1edc5cee053d063f9 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 1 Oct 2013 12:26:19 +0200 Subject: [PATCH] new helper abs_filesystem_path() Returns the absolute path for a . Also activates storage if possible. --- PVE/Storage.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index b38990a..2642396 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -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) = @_;