feat: UI support for emptying shares from an unRAID array disk

This commit is contained in:
Tom Mortensen
2025-09-18 09:48:45 -07:00
parent e50079b544
commit 6522a72d99
3 changed files with 49 additions and 1 deletions
+1 -1
View File
@@ -876,7 +876,7 @@ _(Spin down delay)_:
<?endif;?>
<?if (diskType('Data') || (isPool($tag) && !isSubpool($tag))):?>
_(File system status)_:
: <?=_(_var($disk, 'fsStatus'))?>&nbsp;
: <?=_(_var($disk, 'fsStatus'))?><?=(_var($disk,'fsStatus')==="Mounted")? (_var($disk,'fsEmpty')==="yes"? ", empty" : ", not empty"):""?>&nbsp;
<?if ($fsTypeImmutable):?>
_(File system type)_:
+25
View File
@@ -28,6 +28,7 @@ $fileMax = (int) file_get_contents('/proc/sys/fs/file-max');
$(function() {
$('#s1').dropdownchecklist({emptyText:"_(All)_", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
$('#s2').dropdownchecklist({emptyText:"_(None)_", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
$('#s3').dropdownchecklist({emptyText:"_(None)_", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
presetShare(document.share_settings);
});
@@ -47,6 +48,7 @@ async function prepareShare(form) {
item = form.shareUserInclude.options[0];
item.value = include;
item.selected = true;
var exclude = '';
for (var i=0,item; item=form.shareUserExclude.options[i]; i++) {
if (item.selected) {
@@ -59,6 +61,18 @@ async function prepareShare(form) {
item.value = exclude;
item.selected = true;
var emptying = '';
for (var i=0,item; item=form.shareUserEmptying.options[i]; i++) {
if (item.selected) {
if (emptying.length) emptying += ',';
emptying += item.value;
item.selected = false;
}
}
item = form.shareUserEmptying.options[0];
item.value = emptying;
item.selected = true;
/* Validate file count input against fileMax */
try {
const fileCountInput = form.querySelector('#file_count');
@@ -87,8 +101,10 @@ function presetShare(form,shares) {
var onOff = disabled ? 'disable':'enable';
form.shareUserInclude.disabled = disabled;
form.shareUserExclude.disabled = disabled;
form.shareUserEmptying.disabled = disabled;
$('#s1').dropdownchecklist(onOff);
$('#s2').dropdownchecklist(onOff);
$('#s3').dropdownchecklist(onOff);
}
</script>
<form markdown="1" name="share_settings" method="POST" action="/update.htm" target="progressFrame" onsubmit="return prepareShare(this)">
@@ -128,6 +144,15 @@ _(Excluded disk(s))_:
:shares_excluded_disks_help:
_(Emptying disk(s))_:
: <select id="s3" name="shareUserEmptying" multiple="multiple" style="display:none">
<?foreach ($disks as $disk):?>
<?=mk_option_luks(_var($disk,'name'),_var($var,'shareUserEmptying'),strstr(_var($disk,'fsType'),':',true))?>
<?endforeach;?>
</select>
:shares_emptying_disks_help:
_(Permit exclusive shares)_:
: <select name="shareUserExclusive" <?=$disabled?>>
<?=mk_option($var['shareUserExclusive'], "no", _('No'))?>
+23
View File
@@ -83,6 +83,29 @@ start() {
fi
done
# maybe empty an array disk
EMPTYING=$(grep '^shareUserEmptying=' /boot/config/share.cfg | cut -d'"' -f2)
IFS=',' read -ra arr <<< "$EMPTYING"
for DISK in "${arr[@]}"; do
# we can only empty share directories
for SHAREPATH in /mnt/$DISK/* ; do
SHARE=$(basename "$SHAREPATH")
if [[ -d "$SHAREPATH" && -f "$CFGPATH/$SHARE.cfg" ]]; then
move "$SHAREPATH" "-e"
fi
done
# output list of files which could not be moved
# use 'find' in case huge number of files left in /mnt/$DISK
count=$(find /mnt/$DISK -mindepth 1 | wc -l)
if [ "$count" -gt 0 ]; then
find /mnt/$DISK -mindepth 1 -depth -printf 'move: %p Not moved\n' | head -n 100
if [ "$count" -gt 100 ]; then
echo "[output truncated to first 100 entries]"
fi
fi
done
rm -f $PIDFILE
echo "mover: finished"
}