Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions commands/host/_lib/check-drupal-safe-uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,36 @@ 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
if [[ -n "$LOCK_DIFF" ]] && echo "$LOCK_DIFF" | grep -qE "^-[[:space:]]+\"name\":[[:space:]]+\"drupal/${mod}\""; then
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
Expand Down
Loading