From ff17ec2cd143ba9129f39995265094a2e199d7e6 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Wed, 15 Jul 2026 22:47:05 -0400 Subject: [PATCH] fix(downgrade): block during protected array shrink --- .../include/Downgrade.php | 21 ++++++++++ .../include/ParityProtectedShrinkGuard.php | 22 +++++++++++ .../parity_protected_shrink_guard_test.php | 39 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 emhttp/plugins/dynamix.plugin.manager/include/ParityProtectedShrinkGuard.php create mode 100644 emhttp/plugins/dynamix.plugin.manager/tests/parity_protected_shrink_guard_test.php diff --git a/emhttp/plugins/dynamix.plugin.manager/include/Downgrade.php b/emhttp/plugins/dynamix.plugin.manager/include/Downgrade.php index 9742e7bbc3..4d183e1dac 100644 --- a/emhttp/plugins/dynamix.plugin.manager/include/Downgrade.php +++ b/emhttp/plugins/dynamix.plugin.manager/include/Downgrade.php @@ -14,11 +14,32 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); require_once "$docroot/webGui/include/Wrappers.php"; require_once "$docroot/webGui/include/Secure.php"; +require_once __DIR__.'/ParityProtectedShrinkGuard.php'; // add translations $_SERVER['REQUEST_URI'] = 'plugins'; require_once "$docroot/webGui/include/Translations.php"; +$protectedShrinkFiles = parity_protected_shrink_files(); +$downgradeMarker = '/var/run/unraid-os-downgrade'; +$downgradeMarkerHandle = @fopen($downgradeMarker, 'x'); + +if ($downgradeMarkerHandle === false) { + http_response_code(409); + echo _('An Unraid downgrade is already pending.'); + exit; +} + +fclose($downgradeMarkerHandle); +chmod($downgradeMarker, 0600); + +if (parity_protected_shrink_active($protectedShrinkFiles)) { + unlink($downgradeMarker); + http_response_code(409); + echo _('Finish or recover the active parity-protected disk removal before downgrading Unraid.'); + exit; +} + $tmpdir="/boot/deletemedowngrade.".uniqid(); mkdir($tmpdir); exec("mv -f /boot/bz* $tmpdir"); diff --git a/emhttp/plugins/dynamix.plugin.manager/include/ParityProtectedShrinkGuard.php b/emhttp/plugins/dynamix.plugin.manager/include/ParityProtectedShrinkGuard.php new file mode 100644 index 0000000000..0cc25b952a --- /dev/null +++ b/emhttp/plugins/dynamix.plugin.manager/include/ParityProtectedShrinkGuard.php @@ -0,0 +1,22 @@ + diff --git a/emhttp/plugins/dynamix.plugin.manager/tests/parity_protected_shrink_guard_test.php b/emhttp/plugins/dynamix.plugin.manager/tests/parity_protected_shrink_guard_test.php new file mode 100644 index 0000000000..2b9d53aa7c --- /dev/null +++ b/emhttp/plugins/dynamix.plugin.manager/tests/parity_protected_shrink_guard_test.php @@ -0,0 +1,39 @@ +