From 06284a309cf3a6b7c14b051e252b71b30eef0d5c Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Tue, 23 Jun 2026 16:54:02 +0200 Subject: [PATCH 1/2] fix: no false positive for core module uninstall Check if module code is in codebase, and if it was present before change. Avoids false negatives for custom modules so not relying on composer alone. Also check if composer removed at same time for contrib modules. --- .../host/_lib/check-drupal-safe-uninstall.sh | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/commands/host/_lib/check-drupal-safe-uninstall.sh b/commands/host/_lib/check-drupal-safe-uninstall.sh index e06d6db..bb9d594 100644 --- a/commands/host/_lib/check-drupal-safe-uninstall.sh +++ b/commands/host/_lib/check-drupal-safe-uninstall.sh @@ -26,9 +26,23 @@ if [[ -n "$EXT_FILE" ]] && git -C "$APPROOT" rev-parse --git-dir >/dev/null 2>&1 while IFS= read -r mod; do [[ -z "$mod" ]] && continue - MOD_PATH="" + IS_COMPOSER_PACKAGE=false + if git -C "$APPROOT" show "$DIFF_FROM:$LOCK_FILE" 2>/dev/null | grep -q "\"name\": \"drupal/${mod}\""; then + IS_COMPOSER_PACKAGE=true + fi + + HAD_CODE_BEFORE=false if [[ ${#SEARCH_DIRS[@]} -gt 0 ]]; then - MOD_PATH=$(find "${SEARCH_DIRS[@]}" -maxdepth 5 -type d -name "$mod" ! -path "*/.git/*" 2>/dev/null | head -1) + if git -C "$APPROOT" ls-tree -r "$DIFF_FROM" -- "${SEARCH_DIRS[@]}" 2>/dev/null | grep -q "/${mod}/"; then + HAD_CODE_BEFORE=true + fi + fi + + HAS_CODE_NOW=false + if [[ ${#SEARCH_DIRS[@]} -gt 0 ]]; then + if find "${SEARCH_DIRS[@]}" -maxdepth 5 -type d -name "$mod" ! -path "*/.git/*" 2>/dev/null | grep -q .; then + HAS_CODE_NOW=true + fi fi COMPOSER_REMOVED=false @@ -36,9 +50,12 @@ if [[ -n "$EXT_FILE" ]] && git -C "$APPROOT" rev-parse --git-dir >/dev/null 2>&1 COMPOSER_REMOVED=true fi - if [[ -z "$MOD_PATH" ]] || $COMPOSER_REMOVED; then + if $IS_COMPOSER_PACKAGE && $COMPOSER_REMOVED; then + UNSAFE+=("$mod") + elif ! $IS_COMPOSER_PACKAGE && $HAD_CODE_BEFORE && ! $HAS_CODE_NOW; then UNSAFE+=("$mod") fi + done <<< "$REMOVED_MODULES" if [[ ${#UNSAFE[@]} -gt 0 ]]; then From c8d9562b25d1d8eeaaf6afe431e17aeb104f339e Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Wed, 23 Sep 2026 17:57:50 +0000 Subject: [PATCH 2/2] re-enable safe-uninstall check Now that false positives with uninstalling core modules no longer happening with fix. --- commands/host/sanity-check | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/commands/host/sanity-check b/commands/host/sanity-check index 8d0a380..6f81c79 100755 --- a/commands/host/sanity-check +++ b/commands/host/sanity-check @@ -66,8 +66,7 @@ group "DRUPAL" . "$LIB_DIR/check-drupal-version.sh" . "$LIB_DIR/check-drupal-performance.sh" . "$LIB_DIR/check-drupal-extensions.sh" -# DISABLED: buggy — re-enable when fixed -# . "$LIB_DIR/check-drupal-safe-uninstall.sh" +. "$LIB_DIR/check-drupal-safe-uninstall.sh" . "$LIB_DIR/check-drupal-files-view.sh" . "$LIB_DIR/check-drupal-simplei.sh" . "$LIB_DIR/check-drupal-gin.sh"