Fix delete VM if in a dataset.

This commit is contained in:
SimonFair
2024-07-24 21:20:06 +01:00
parent e20f37d936
commit d272bf78ac
2 changed files with 24 additions and 1 deletions

View File

@@ -1989,7 +1989,8 @@
if (is_file($disk)) unlink($disk);
if (is_file($cfg)) unlink($cfg);
if (is_file($xml)) unlink($xml);
if (is_dir($dir) && $this->is_dir_empty($dir)) rmdir($dir);
#if (is_dir($dir) && $this->is_dir_empty($dir)) rmdir($dir);
if (is_dir($dir) && $this->is_dir_empty($dir)) my_rmdir($dir);
}
return true;

View File

@@ -308,6 +308,28 @@ function my_mkdir($dirname,$permissions = 0777,$recursive = false,$own = "nobody
chgrp($dirname, $grp);
return($rtncode);
}
function my_rmdir($dirname) {
if (!is_dir($dirname)) return(false);
if (strpos($dirname,'/mnt/user/')===0) {
$realdisk = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($dirname)." 2>/dev/null"));
if (!empty($realdisk)) {
$dirname = str_replace('/mnt/user/', "/mnt/$realdisk/", $dirname);
}
}
$fstype = trim(shell_exec(" stat -f -c '%T' $dirname"));
$rtncode = false;
switch ($fstype) {
case "zfs":
$zfsdataset = trim(shell_exec("zfs list -H -o name $dirname")) ;
$rtncode=exec("zfs destroy \"$zfsdataset\"");
break;
case "btrfs":
default:
$rtncode = rmdir($dirname);
break;
}
return($rtncode);
}
function get_realvolume($path) {
if (strpos($path,"/mnt/user/",0) === 0)
$reallocation = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($path)." 2>/dev/null"));