From a48ebfc4c10e2364f509dc3c494b2c33fe2efbb7 Mon Sep 17 00:00:00 2001 From: Bishoy Ehab Date: Sun, 19 Oct 2025 00:40:00 +0300 Subject: [PATCH] Fixed the test and update script --- sdata/step/exp-update-tester.sh | 38 +++++++++++++++++++-------------- sdata/step/exp-update.sh | 17 +++++++++++---- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/sdata/step/exp-update-tester.sh b/sdata/step/exp-update-tester.sh index ef1823abd..cfdcbd56e 100755 --- a/sdata/step/exp-update-tester.sh +++ b/sdata/step/exp-update-tester.sh @@ -155,13 +155,14 @@ DRY_RUN=false FORCE_CHECK=false VERBOSE=false NON_INTERACTIVE=true +SOURCE_ONLY=true source "$ORIGINAL_DIR/sdata/step/exp-update.sh" -detected_dirs=$(detect_repo_structure) -if [[ -n "$detected_dirs" ]]; then - read -ra MONITOR_DIRS <<<"$detected_dirs" +detected_dirs=\$(detect_repo_structure) +if [[ -n "\$detected_dirs" ]]; then + read -ra MONITOR_DIRS <<<"\$detected_dirs" fi -echo "Structure: ${MONITOR_DIRS[*]}" +echo "Structure: \${MONITOR_DIRS[*]}" EOF chmod +x test_detection.sh @@ -214,13 +215,14 @@ DRY_RUN=false FORCE_CHECK=false VERBOSE=false NON_INTERACTIVE=true +SOURCE_ONLY=true source "$ORIGINAL_DIR/sdata/step/exp-update.sh" -detected_dirs=$(detect_repo_structure) -if [[ -n "$detected_dirs" ]]; then - read -ra MONITOR_DIRS <<<"$detected_dirs" +detected_dirs=\$(detect_repo_structure) +if [[ -n "\$detected_dirs" ]]; then + read -ra MONITOR_DIRS <<<"\$detected_dirs" fi -echo "Structure: ${MONITOR_DIRS[*]}" +echo "Structure: \${MONITOR_DIRS[*]}" EOF chmod +x test_detection.sh @@ -515,15 +517,17 @@ test_lock_file() { echo "99999" > .update-lock # Try to run update - should fail due to lock - if ./install.sh exp-update --skip-notice --non-interactive 2>&1 | grep -q "stale lock"; then - log_pass "Lock file mechanism works (detected stale lock)" - cd "$ORIGINAL_DIR" - return 0 - else - log_fail "Lock file mechanism did not work as expected" - cd "$ORIGINAL_DIR" - return 1 + if ./install.sh exp-update --skip-notice --non-interactive > lock_test_output.txt 2>&1; then + if grep -q "stale lock" lock_test_output.txt; then + log_pass "Lock file mechanism works (detected stale lock)" + cd "$ORIGINAL_DIR" + return 0 + fi fi + log_fail "Lock file mechanism did not work as expected" + cat lock_test_output.txt # Show output for debugging + cd "$ORIGINAL_DIR" + return 1 } # Test 13: Test ** substring ignore patterns - FIXED @@ -657,6 +661,7 @@ DRY_RUN=false FORCE_CHECK=false VERBOSE=false NON_INTERACTIVE=true +SOURCE_ONLY=true source "$ORIGINAL_DIR/sdata/step/exp-update.sh" 2>/dev/null @@ -825,6 +830,7 @@ cleanup() { cleanup_test_env rm -f test_detection.sh test_ignore.sh test_safe_read.sh test_fresh_clone.sh test_substring_ignore.sh dry_run_output.txt 2>/dev/null || true rm -f test_caching.sh test_dir_cache.sh 2>/dev/null || true + rm -f lock_test_output.txt 2>/dev/null || true rm -rf "${HOME}/.config/test-app" 2>/dev/null || true } diff --git a/sdata/step/exp-update.sh b/sdata/step/exp-update.sh index 640707d28..2cadb75a4 100755 --- a/sdata/step/exp-update.sh +++ b/sdata/step/exp-update.sh @@ -160,10 +160,16 @@ load_ignore_patterns() { [[ -z "$pattern" ]] && continue # Separate substring patterns from regular patterns - if [[ "$pattern" == \*\** ]]; then + if [[ "${pattern:0:2}" == "**" ]]; then local cleaned_pattern="${pattern#\*\*}" - cleaned_pattern="${cleaned_pattern%%*}" - IGNORE_SUBSTRING_PATTERNS+=("$cleaned_pattern") + # Strip trailing asterisks + while [[ "$cleaned_pattern" == *"*" ]] && [[ "${cleaned_pattern: -1}" == "*" ]]; do + cleaned_pattern="${cleaned_pattern%\*}" + done + # Ensure we have a non-empty pattern + if [[ -n "$cleaned_pattern" ]]; then + IGNORE_SUBSTRING_PATTERNS+=("$cleaned_pattern") + fi else IGNORE_PATTERNS+=("$pattern") fi @@ -716,12 +722,13 @@ cleanup_on_exit() { } # Set up signal handling and lock file +if [[ "${SOURCE_ONLY:-false}" != true ]]; then trap cleanup_on_exit EXIT INT TERM # Check for concurrent runs if [[ -f "${REPO_ROOT}/.update-lock" ]]; then # Check if the process is still running - if kill -0 $(cat "${REPO_ROOT}/.update-lock" 2>/dev/null) 2>/dev/null; then + if kill -0 "$(cat "${REPO_ROOT}/.update-lock" 2>/dev/null)" 2>/dev/null; then log_die "Another update is already running (PID: $(cat "${REPO_ROOT}/.update-lock"))" else log_warning "Found stale lock file, removing..." @@ -1138,4 +1145,6 @@ if [[ -d "${REPO_ROOT}/.update-backups" ]] && [[ "$DRY_RUN" != true ]]; then log_info "Backups stored in: ${REPO_ROOT}/.update-backups/" fi +fi + echo \ No newline at end of file