Fix detection of unmountable disk when checking for no mountable disks .

This commit is contained in:
dlandon
2024-05-19 07:05:51 -05:00
parent cebe945e81
commit a5cab82c29
3 changed files with 98 additions and 34 deletions

View File

@@ -28,6 +28,13 @@ $var = parse_ini_file('state/var.ini');
$sec = parse_ini_file('state/sec.ini',true);
$sec_nfs = parse_ini_file('state/sec_nfs.ini',true);
/* Get the pools from the disks.ini. */
$pools_check = pools_filter(cache_filter($disks));
$pools = implode(',', $pools_check);
/* If the configuration is pools only, then no array disks are available. */
$poolsOnly = ((int)$var['sbNumDisks'] == 2) ? true : false;
// exit when no mountable array disks
$nodisks = "<tr><td class='empty' colspan='7'><strong>"._('There are no mountable array or pool disks - cannot add shares').".</strong></td></tr>";
if (!checkDisks($disks)) die($nodisks);
@@ -38,18 +45,28 @@ $nodisks = "<tr><td class='empty' colspan='7'><i class='fa fa-folder-open-o icon
// GUI settings
extract(parse_plugin_cfg('dynamix',true));
// Function to filter out unwanted disks, check if any valid disks exist, and ignore disks with a blank device.
/* Function to filter out unwanted disks, check if any valid disks exist, and ignore disks with a blank device. */
function checkDisks($disks) {
foreach ($disks as $disk) {
// Check the disk type, fsStatus, and ensure the device is not blank.
if (!in_array($disk['name'], ['flash', 'parity', 'parity2']) && $disk['fsStatus'] !== "Unmountable: unsupported or no file system" && !empty($disk['device'])) {
// A valid disk with a non-blank device is found, return true.
return true;
}
}
global $pools, $poolsOnly;
// No valid disks found, return false.
return false;
$rc = false;
if (!$poolsOnly) {
foreach ($disks as $disk) {
/* Check the disk type, fsStatus, and ensure the device is not blank. */
if (!in_array($disk['name'], ['flash', 'parity', 'parity2']) && strpos($disk['fsStatus'], 'Unmountable') === false && !empty($disk['device'])) {
/* A valid disk with a non-blank device is found. */
$rc = true;
break;
}
}
} else {
/* See if there are any pools. */
$rc = !empty($pools);
}
return $rc;
}
// Display export settings

View File

@@ -18,9 +18,29 @@ require_once "$docroot/webGui/include/Helpers.php";
$_SERVER['REQUEST_URI'] = 'shares';
require_once "$docroot/webGui/include/Translations.php";
/* Check for any files in the share. */
if (isset($_POST['scan'])) {
die((new FilesystemIterator("/mnt/user/{$_POST['scan']}"))->valid() ? '0' : '1');
$dirPath = "/mnt/user/{$_POST['scan']}";
/* Check if the directory exists. */
if (!is_dir($dirPath)) {
die('1'); // Directory does not exist
}
$iterator = new FilesystemIterator($dirPath);
$hasNonDSStoreFiles = false;
/* Iterate over the directory contents. */
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile() && $fileinfo->getFilename() !== '.DS_Store') {
$hasNonDSStoreFiles = true;
break;
}
}
die($hasNonDSStoreFiles ? '0' : '1');
}
if (isset($_POST['cleanup'])) {
$n = 0;
// active shares
@@ -46,6 +66,13 @@ $var = parse_ini_file('state/var.ini');
$sec = parse_ini_file('state/sec.ini',true);
$sec_nfs = parse_ini_file('state/sec_nfs.ini',true);
/* Get the pools from the disks.ini. */
$pools_check = pools_filter(cache_filter($disks));
$pools = implode(',', $pools_check);
/* If the configuration is pools only, then no array disks are available. */
$poolsOnly = ((int)$var['sbNumDisks'] == 2) ? true : false;
// exit when no mountable array disks
$nodisks = "<tr><td class='empty' colspan='7'><strong>"._('There are no mountable array or pool disks - cannot add shares').".</strong></td></tr>";
if (!checkDisks($disks)) die($nodisks);
@@ -57,24 +84,31 @@ if (!$shares) die($noshares);
// GUI settings
extract(parse_plugin_cfg('dynamix',true));
$pools_check = pools_filter(cache_filter($disks));
$pools = implode(',', $pools_check);
// Natural sorting of share names
uksort($shares,'strnatcasecmp');
// Function to filter out unwanted disks, check if any valid disks exist, and ignore disks with a blank device.
/* Function to filter out unwanted disks, check if any valid disks exist, and ignore disks with a blank device. */
function checkDisks($disks) {
foreach ($disks as $disk) {
// Check the disk type, fsStatus, and ensure the device is not blank.
if (!in_array($disk['name'], ['flash', 'parity', 'parity2']) && $disk['fsStatus'] !== "Unmountable: unsupported or no file system" && !empty($disk['device'])) {
// A valid disk with a non-blank device is found, return true.
return true;
}
}
global $pools, $poolsOnly;
// No valid disks found, return false.
return false;
$rc = false;
if (!$poolsOnly) {
foreach ($disks as $disk) {
/* Check the disk type, fsStatus, and ensure the device is not blank. */
if (!in_array($disk['name'], ['flash', 'parity', 'parity2']) && strpos($disk['fsStatus'], 'Unmountable') === false && !empty($disk['device'])) {
/* A valid disk with a non-blank device is found. */
$rc = true;
break;
}
}
} else {
/* See if there are any pools. */
$rc = !empty($pools);
}
return $rc;
}
// Display export settings