From 216661f426428882a2122bd52c53eb9f82bd5a43 Mon Sep 17 00:00:00 2001 From: Niclas Berglind Date: Tue, 16 Sep 2014 22:34:31 +0200 Subject: [PATCH] Fix to clean up OMV shared folders when deleting shared datasets. Signed-off-by: Niclas Berglind --- gui/rpc/zfs.inc | 14 +++++++------- src/Utils.php | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/gui/rpc/zfs.inc b/gui/rpc/zfs.inc index af69ec4..75c22eb 100644 --- a/gui/rpc/zfs.inc +++ b/gui/rpc/zfs.inc @@ -125,6 +125,11 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); switch ($params['type']) { case "Filesystem": + $name = $params['name']; + OMVModuleZFSUtil::deleteShares($name); + $tmp = new OMVModuleZFSDataset($name); + $tmp->destroy(); + break; case "Clone": $name = $params['name']; $tmp = new OMVModuleZFSDataset($name); @@ -272,7 +277,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname); //Get the mntent object and fetch it's uuid. - $xpath = "//system/fstab/mntent[fsname=" . $pooluuid . "]"; + $xpath = "//system/fstab/mntent[fsname='" . $pooluuid . "']"; $mountpoint = $xmlConfig->get($xpath); $mntentref = $mountpoint['uuid']; @@ -292,12 +297,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $uuid = OMVUtil::uuid(); $pathName = $tmp->getMountPoint(); - $subdirs = preg_split('/\//',$pathName); - $reldirpath = ""; - for ($i=2;$i $uuid, "name" => $params['sharename'], diff --git a/src/Utils.php b/src/Utils.php index f997041..a6bb3ee 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -8,6 +8,40 @@ require_once("Dataset.php"); */ class OMVModuleZFSUtil { + /** + * Deletes all shared folders pointing to the specifc path + * + */ + public static function deleteShares($name) { + global $xmlConfig; + $tmp = new OMVModuleZFSDataset($name); + $reldirpath = OMVModuleZFSUtil::getReldirpath($tmp->getMountPoint()); + $poolname = OMVModuleZFSUtil::getPoolname($name); + $pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname); + $xpath = "//system/fstab/mntent[fsname='" . $pooluuid . "']"; + $mountpoint = $xmlConfig->get($xpath); + $mntentuuid = $mountpoint['uuid']; + $xpath = "//system/shares/sharedfolder[mntentref='" . $mntentuuid . "' and reldirpath='" . $reldirpath . "']"; + $xmlConfig->delete($xpath); + $dispatcher = &OMVNotifyDispatcher::getInstance(); + $dispatcher->notify(OMV_NOTIFY_CREATE,"org.openmediavault.system.shares.sharedfolder"); + } + + /** + * Get the relative path by complete path + * + * @return string Relative path of the complet path + */ + public static function getReldirpath($path) { + $subdirs = preg_split('/\//',$path); + $reldirpath = ""; + for ($i=2;$iget($xpath); if (is_null($mountpoint)) { $uuid = OMVUtil::uuid(); -- 2.39.2