Fix the local used outside a function issue

This commit is contained in:
Bishoy Ehab
2025-10-16 23:38:18 +03:00
parent 00d4d368df
commit 009345c5f6
+35 -15
View File
@@ -500,7 +500,7 @@ build_packages() {
fi fi
for pkg_name in "${packages_to_build[@]}"; do for pkg_name in "${packages_to_build[@]}"; do
local pkg_dir="${ARCH_PACKAGES_DIR}/${pkg_name}" pkg_dir="${ARCH_PACKAGES_DIR}/${pkg_name}"
if [[ ! -d "$pkg_dir" || ! -f "${pkg_dir}/PKGBUILD" ]]; then if [[ ! -d "$pkg_dir" || ! -f "${pkg_dir}/PKGBUILD" ]]; then
log_error "Package not found or missing PKGBUILD: $pkg_name" log_error "Package not found or missing PKGBUILD: $pkg_name"
@@ -674,10 +674,14 @@ if detected_dirs=$(detect_repo_structure); then
read -ra MONITOR_DIRS <<<"$detected_dirs" read -ra MONITOR_DIRS <<<"$detected_dirs"
log_success "Detected repository structure:" log_success "Detected repository structure:"
for dir in "${MONITOR_DIRS[@]}"; do for dir in "${MONITOR_DIRS[@]}"; do
log_info " - ${REPO_DIR}/${dir}" if [[ -d "${REPO_DIR}/${dir}" ]]; then
log_info "${REPO_DIR}/${dir}"
else
log_warning "${REPO_DIR}/${dir} (not found, will skip)"
fi
done done
else else
die "Failed to detect repository structure" die "Failed to detect repository structure. Make sure you're in the correct directory."
fi fi
# Step 1: Pull latest commits # Step 1: Pull latest commits
@@ -737,12 +741,12 @@ if [[ "$CHECK_PACKAGES" == true ]]; then
log_header "Package Management" log_header "Package Management"
if [[ ! -d "$ARCH_PACKAGES_DIR" ]]; then if [[ ! -d "$ARCH_PACKAGES_DIR" ]]; then
log_warning "No sdist/arch directory found. Skipping package management." log_warning "No packages directory found (tried: dist-arch, arch-packages, sdist/arch). Skipping package management."
else else
changed_pkgbuilds=() changed_pkgbuilds=()
for pkg_dir in "$ARCH_PACKAGES_DIR"/*/; do for pkg_dir in "$ARCH_PACKAGES_DIR"/*/; do
if [[ -f "${pkg_dir}/PKGBUILD" ]]; then if [[ -f "${pkg_dir}/PKGBUILD" ]]; then
local pkg_name=$(basename "$pkg_dir") pkg_name=$(basename "$pkg_dir")
if check_pkgbuild_changed "$pkg_dir"; then if check_pkgbuild_changed "$pkg_dir"; then
changed_pkgbuilds+=("$pkg_name") changed_pkgbuilds+=("$pkg_name")
fi fi
@@ -844,6 +848,13 @@ if [[ "$process_files" == true ]]; then
for dir_name in "${MONITOR_DIRS[@]}"; do for dir_name in "${MONITOR_DIRS[@]}"; do
repo_dir_path="${REPO_DIR}/${dir_name}" repo_dir_path="${REPO_DIR}/${dir_name}"
if [[ ! -d "$repo_dir_path" ]]; then
if [[ "$VERBOSE" == true ]]; then
log_warning "Skipping non-existent directory: $repo_dir_path"
fi
continue
fi
# Calculate the target home directory properly # Calculate the target home directory properly
if [[ "$dir_name" == dots/* ]]; then if [[ "$dir_name" == dots/* ]]; then
# Strip "dots/" prefix for home directory # Strip "dots/" prefix for home directory
@@ -854,11 +865,6 @@ if [[ "$process_files" == true ]]; then
home_dir_path="${HOME}/${dir_name}" home_dir_path="${HOME}/${dir_name}"
fi fi
if [[ ! -d "$repo_dir_path" ]]; then
log_warning "Repository directory not found: $repo_dir_path"
continue
fi
log_info "Processing directory: $dir_name${home_dir_path}" log_info "Processing directory: $dir_name${home_dir_path}"
mkdir -p "$home_dir_path" mkdir -p "$home_dir_path"
@@ -879,12 +885,21 @@ if [[ "$process_files" == true ]]; then
if [[ -f "$home_file" ]]; then if [[ -f "$home_file" ]]; then
if ! cmp -s "$repo_file" "$home_file"; then if ! cmp -s "$repo_file" "$home_file"; then
log_info "Found difference in: $rel_path" log_info "Found difference in: $rel_path"
handle_file_conflict "$repo_file" "$home_file" if [[ "$DRY_RUN" == true ]]; then
((files_updated++)) log_warning "[DRY-RUN] Conflict detected (would prompt): $home_file"
((files_updated++))
else
handle_file_conflict "$repo_file" "$home_file"
((files_updated++))
fi
fi fi
else else
cp -p "$repo_file" "$home_file" if [[ "$DRY_RUN" == true ]]; then
log_success "Created new file: $home_file" log_info "[DRY-RUN] Would create new file: $home_file"
else
cp -p "$repo_file" "$home_file"
log_success "Created new file: $home_file"
fi
((files_created++)) ((files_created++))
fi fi
done < <(get_changed_files "$repo_dir_path") done < <(get_changed_files "$repo_dir_path")
@@ -908,7 +923,12 @@ if [[ -d "${HOME}/.local/bin" ]]; then
fi fi
log_header "Update Complete" log_header "Update Complete"
log_success "Dotfiles update completed successfully!" if [[ "$DRY_RUN" == true ]]; then
log_warning "DRY-RUN MODE: No changes were actually made"
log_info "Run without -n/--dry-run to apply changes"
else
log_success "Dotfiles update completed successfully!"
fi
echo echo
echo -e "${CYAN}Summary:${NC}" echo -e "${CYAN}Summary:${NC}"