fix: reorder logic in link_model() and verify_model_links() to check file_mappings first
Previously, both functions called find_model_files() with empty filters before checking for explicit file mappings, causing premature exit when filters were empty. Now both functions check for file_mappings FIRST, then call find_model_files() only after confirming mappings exist. This fixes critical linking failures for models with explicit file mappings but no filename filters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -579,71 +579,50 @@ link_model() {
|
||||
local filename_filter="$2"
|
||||
local file_mappings="$3" # Optional: explicit source|dest mappings
|
||||
|
||||
# Extract unique target directories from file mappings
|
||||
local target_dirs=()
|
||||
if [[ -n "$file_mappings" ]]; then
|
||||
while IFS='|' read -r source_pattern dest_path; do
|
||||
if [[ -n "$dest_path" && "$dest_path" == *"/"* ]]; then
|
||||
local dir_path="${dest_path%/*}"
|
||||
target_dirs+=("${COMFYUI_DIR}/${dir_path}")
|
||||
fi
|
||||
done <<< "$file_mappings"
|
||||
fi
|
||||
|
||||
# Remove duplicates from target_dirs array
|
||||
local unique_dirs=($(printf '%s\n' "${target_dirs[@]}" | sort -u))
|
||||
|
||||
if [[ ${#unique_dirs[@]} -eq 0 ]]; then
|
||||
print_warning "No target directories found in file mappings"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Display target directories
|
||||
for target_dir in "${unique_dirs[@]}"; do
|
||||
print_detail "Linking to: ${CYAN}${target_dir}/${RESET}"
|
||||
|
||||
# Create ComfyUI subdirectory if it doesn't exist
|
||||
if [[ ! -d "$target_dir" ]]; then
|
||||
print_info "Creating directory: ${CYAN}${target_dir}${RESET}"
|
||||
mkdir -p "$target_dir"
|
||||
fi
|
||||
|
||||
# Clean existing symlinks for this repo in the target directory
|
||||
# This ensures we start fresh and don't have stale links
|
||||
find "$target_dir" -type l -lname "*${repo_id/\//-}*" -delete 2>/dev/null || true
|
||||
done
|
||||
|
||||
# Find model files in cache
|
||||
local model_files
|
||||
model_files=$(find_model_files "$repo_id" "$filename_filter")
|
||||
|
||||
if [[ -z "$model_files" ]]; then
|
||||
print_warning "No model files found in cache for ${repo_id}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Count files
|
||||
local file_count
|
||||
file_count=$(echo "$model_files" | grep -c .)
|
||||
|
||||
# Dry-run mode: show what would be linked
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_info "DRY-RUN: Would link ${BOLD_YELLOW}${file_count}${RESET} file(s)"
|
||||
print_detail "Files that would be linked:"
|
||||
while IFS='|' read -r source_pattern dest_path; do
|
||||
if [[ -n "$dest_path" ]]; then
|
||||
print_detail " ${LINK} Would link: ${DIM}${dest_path}${RESET}"
|
||||
fi
|
||||
done <<< "$file_mappings"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local linked_count=0
|
||||
|
||||
# If explicit file mappings are provided, use them
|
||||
if [[ -n "$file_mappings" ]]; then
|
||||
print_detail "Using explicit file mappings from YAML"
|
||||
|
||||
# Extract unique target directories from file mappings for display
|
||||
local target_dirs=()
|
||||
while IFS='|' read -r source_pattern dest_path; do
|
||||
if [[ -n "$dest_path" && "$dest_path" == *"/"* ]]; then
|
||||
local dir_path="${dest_path%/*}"
|
||||
target_dirs+=("${COMFYUI_DIR}/${dir_path}")
|
||||
fi
|
||||
done <<< "$file_mappings"
|
||||
|
||||
# Remove duplicates and display
|
||||
local unique_dirs=($(printf '%s\n' "${target_dirs[@]}" | sort -u))
|
||||
for target_dir in "${unique_dirs[@]}"; do
|
||||
print_detail "Linking to: ${CYAN}${target_dir}/${RESET}"
|
||||
done
|
||||
|
||||
# Dry-run mode: show what would be linked
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
local file_count=$(echo "$file_mappings" | grep -c .)
|
||||
print_info "DRY-RUN: Would link ${BOLD_YELLOW}${file_count}${RESET} file(s)"
|
||||
print_detail "Files that would be linked:"
|
||||
while IFS='|' read -r source_pattern dest_path; do
|
||||
if [[ -n "$dest_path" ]]; then
|
||||
print_detail " ${LINK} Would link: ${DIM}${dest_path}${RESET}"
|
||||
fi
|
||||
done <<< "$file_mappings"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Find all model files in cache (no filter needed, we have explicit paths)
|
||||
local model_files
|
||||
model_files=$(find_model_files "$repo_id" "")
|
||||
|
||||
if [[ -z "$model_files" ]]; then
|
||||
print_warning "No model files found in cache for ${repo_id}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Process each file mapping
|
||||
while IFS='|' read -r source_pattern dest_path; do
|
||||
if [[ -z "$source_pattern" ]] || [[ -z "$dest_path" ]]; then
|
||||
continue
|
||||
@@ -1075,15 +1054,6 @@ verify_model_links() {
|
||||
local filename_filter="$2"
|
||||
local file_mappings="$3"
|
||||
|
||||
# Find model files in cache
|
||||
local model_files
|
||||
model_files=$(find_model_files "$repo_id" "$filename_filter" 2>/dev/null)
|
||||
|
||||
if [[ -z "$model_files" ]]; then
|
||||
echo "NOT_DOWNLOADED|0|0|0"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local total_links=0
|
||||
local valid_links=0
|
||||
local broken_links=0
|
||||
@@ -1091,6 +1061,15 @@ verify_model_links() {
|
||||
|
||||
# Check if explicit file mappings exist
|
||||
if [[ -n "$file_mappings" ]]; then
|
||||
# Verify files exist in cache (no filter needed)
|
||||
local model_files
|
||||
model_files=$(find_model_files "$repo_id" "" 2>/dev/null)
|
||||
|
||||
if [[ -z "$model_files" ]]; then
|
||||
echo "NOT_DOWNLOADED|0|0|0"
|
||||
return 1
|
||||
fi
|
||||
|
||||
while IFS='|' read -r source_pattern dest_path; do
|
||||
if [[ -z "$source_pattern" ]] || [[ -z "$dest_path" ]]; then
|
||||
continue
|
||||
@@ -1118,6 +1097,14 @@ verify_model_links() {
|
||||
done <<< "$file_mappings"
|
||||
else
|
||||
# No explicit mappings, check automatic prefixed filenames
|
||||
local model_files
|
||||
model_files=$(find_model_files "$repo_id" "$filename_filter" 2>/dev/null)
|
||||
|
||||
if [[ -z "$model_files" ]]; then
|
||||
echo "NOT_DOWNLOADED|0|0|0"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local model_name
|
||||
model_name=$(echo "$repo_id" | sed 's/.*\///')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user