From b23bdb01889efc991e2e49c164eb237bbb0f75cf Mon Sep 17 00:00:00 2001 From: Bishoy Ehab Date: Sun, 19 Oct 2025 00:07:54 +0300 Subject: [PATCH] Test --- sdata/lib/functions.sh | 7 +++---- sdata/step/exp-update-tester.sh | 15 +++++++++++---- sdata/step/exp-update.sh | 13 ++++++------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/sdata/lib/functions.sh b/sdata/lib/functions.sh index d9a548c93..62024d683 100644 --- a/sdata/lib/functions.sh +++ b/sdata/lib/functions.sh @@ -62,7 +62,7 @@ function x(){ function showfun(){ echo -e "${STY_BLUE}[$0]: The definition of function \"$1\" is as follows:${STY_RST}" printf "${STY_GREEN}" - type -a $1 + type -a "$1" 2>/dev/null || type -a "$1".sh 2>/dev/null || return 1 printf "${STY_RST}" } function pause(){ @@ -73,8 +73,7 @@ function pause(){ fi } function remove_bashcomments_emptylines(){ - mkdir -p $(dirname $2) - cat $1 | sed -e '/^[[:blank:]]*#/d;s/#.*//' -e '/^[[:space:]]*$/d' > $2 + mkdir -p "$(dirname "$2")" && cat "$1" | sed -e 's/#.*//' -e '/^[[:space:]]*$/d' > "$2" } function prevent_sudo_or_root(){ case $(whoami) in @@ -95,7 +94,7 @@ function latest_commit_timestamp(){ echo "[latest_commit_timestamp] The timestamp of \"$target_path\" is empty. Aborting..." >&2 return 1 fi - echo $result + echo "$result" } function log_info() { diff --git a/sdata/step/exp-update-tester.sh b/sdata/step/exp-update-tester.sh index 8ceb5d8ae..ef1823abd 100755 --- a/sdata/step/exp-update-tester.sh +++ b/sdata/step/exp-update-tester.sh @@ -157,7 +157,11 @@ VERBOSE=false NON_INTERACTIVE=true source "$ORIGINAL_DIR/sdata/step/exp-update.sh" -detect_repo_structure +detected_dirs=$(detect_repo_structure) +if [[ -n "$detected_dirs" ]]; then + read -ra MONITOR_DIRS <<<"$detected_dirs" +fi +echo "Structure: ${MONITOR_DIRS[*]}" EOF chmod +x test_detection.sh @@ -212,7 +216,11 @@ VERBOSE=false NON_INTERACTIVE=true source "$ORIGINAL_DIR/sdata/step/exp-update.sh" -detect_repo_structure +detected_dirs=$(detect_repo_structure) +if [[ -n "$detected_dirs" ]]; then + read -ra MONITOR_DIRS <<<"$detected_dirs" +fi +echo "Structure: ${MONITOR_DIRS[*]}" EOF chmod +x test_detection.sh @@ -507,7 +515,7 @@ 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 --dry-run 2>&1 | grep -q "stale lock"; then + 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 @@ -780,7 +788,6 @@ main() { "test_flags" "test_shellcheck" "test_lock_file" - "test_ignore_pattern_caching" "test_directory_caching" "test_safe_read_noninteractive" ) diff --git a/sdata/step/exp-update.sh b/sdata/step/exp-update.sh index db200a85d..640707d28 100755 --- a/sdata/step/exp-update.sh +++ b/sdata/step/exp-update.sh @@ -49,9 +49,6 @@ declare -A CREATED_DIRS # TODO: Is this really needed? `git pull` should do a full upgrade, not partially, which means this script will be updated along with the folder structure together. # Auto-detect repository structure detect_repo_structure() { - if which pacman &>/dev/null; then - return - fi local found_dirs=() # Check for dots/ prefixed structure @@ -164,7 +161,9 @@ load_ignore_patterns() { # Separate substring patterns from regular patterns if [[ "$pattern" == \*\** ]]; then - IGNORE_SUBSTRING_PATTERNS+=("${pattern#\*\*}") + local cleaned_pattern="${pattern#\*\*}" + cleaned_pattern="${cleaned_pattern%%*}" + IGNORE_SUBSTRING_PATTERNS+=("$cleaned_pattern") else IGNORE_PATTERNS+=("$pattern") fi @@ -720,7 +719,7 @@ cleanup_on_exit() { trap cleanup_on_exit EXIT INT TERM # Check for concurrent runs -if [[ -f "${REPO_ROOT}/.update-lock" ]] && [[ "$DRY_RUN" != true ]]; then +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 log_die "Another update is already running (PID: $(cat "${REPO_ROOT}/.update-lock"))" @@ -963,8 +962,8 @@ elif has_new_commits; then process_files=true log_info "New commits detected: checking changed configuration files" else - log_info "No new commits found: checking for local file differences" - process_files=true + log_info "No new commits found and force mode not enabled: skipping file updates" + process_files=false fi if [[ "$process_files" == true ]]; then