Skip to content

Conversation

@diodiogod
Copy link
Contributor

Problem

Users need to move models between drives for backup/organization while preserving their existing custom folder structures. For example, moving models from Models\Lora\Clothes\Pants to a new drive at SD1.5\Lora\Clothes\Pants while maintaining the custom subfolder organization.

Solution

Added {original_path} placeholder support to the existing path template system. This placeholder extracts the relative folder path from the model's current location (excluding the filename) and can be combined with other placeholders.

Usage Examples

Move Modal:

  • Template: {original_path} → Preserves current folder structure
  • Template: {base_model}/{original_path} → Adds base model prefix to current structure
  • Combines with folder browser: Select subfolder + use template

Auto-Organize (Settings → Download Paths):

  • Set download path template to {base_model}/{original_path} for structured organization

Implementation Details

Backend Changes

  • py/utils/utils.py: Extended calculate_relative_path_for_model() to support {original_path} placeholder using os.path.relpath()
  • py/services/model_file_service.py:
    • Added model_type parameter to ModelMoveService.__init__()
    • Updated move_model() to accept and process path_template parameter
    • Fixed auto-organize to pass model_roots for {original_path} calculation
  • py/routes/base_model_routes.py: Fixed ModelMoveService instantiation to pass model_type
  • py/routes/handlers/model_handlers.py: Added path_template parameter extraction from request JSON

Frontend Changes

  • static/js/utils/constants.js: Added {original_path} to PATH_TEMPLATE_PLACEHOLDERS for validation
  • static/js/managers/MoveManager.js:
    • Added path template input reading
    • Modified to combine folder browser selection with template
  • static/js/api/baseModelApi.js: Updated API methods to send path_template parameter
  • static/js/managers/SettingsManager.js: Updated preview logic to show {original_path} examples
  • templates/components/modals/move_modal.html: Added path template input field with help text
  • templates/components/modals/settings_modal.html: Added {original_path} to placeholder documentation
  • locales/en.json: Added translation keys for new UI elements

Manual Verification

✅ Tested moving models with {original_path} template
✅ Tested the "Source and target directories are the same" scenario
✅ Tested combining folder browser with template
✅ Tested {base_model}/{original_path} in auto-organize settings
✅ Verified validation error and fix for {original_path} placeholder

Notes

  • {original_path} extracts the current relative path from the model root, not a "first-seen" path
  • If models are already in organized folders and moved again with {original_path}, it will include the current organization in the new path
  • This is expected behavior - users should be aware of this when using the placeholder

Files Changed

  • py/utils/utils.py
  • py/services/model_file_service.py
  • py/routes/base_model_routes.py
  • py/routes/handlers/model_handlers.py
  • static/js/utils/constants.js
  • static/js/managers/MoveManager.js
  • static/js/managers/SettingsManager.js
  • static/js/api/baseModelApi.js
  • templates/components/modals/move_modal.html
  • templates/components/modals/settings_modal.html
  • locales/en.json

…ucture

Adds support for {original_path} placeholder in path templates, allowing users
to preserve existing custom folder structures when moving or auto-organizing models
across different drives or directories.

Features:
- New {original_path} placeholder extracts relative path from model root
- Works in both Move modal and Auto-Organize settings
- Combines with other placeholders (e.g., {base_model}/{original_path})
- Combines with folder browser selection in Move modal
- Includes validation and preview support in Settings

Backend changes:
- Extended calculate_relative_path_for_model() to support {original_path}
- Added model_type parameter to ModelMoveService for template processing
- Updated auto-organize to pass model_roots for path calculation
- Added path_template parameter to move endpoints

Frontend changes:
- Added path template input field to Move modal
- Updated placeholder validation in constants.js
- Enhanced SettingsManager preview to show {original_path} examples
- Modified MoveManager to combine folder selection with templates

Manual verification:
- Tested moving models with {original_path} template
- Tested auto-organize with {original_path} in download path settings
- Verified template validation and preview display
- Confirmed folder browser + template combination works correctly
@brendanhoar
Copy link

brendanhoar commented Oct 19, 2025

Quick Q: does this (or the existing functionality) verify that the target folderpath/filename.ext length does not exceed the max pathlength for the filesystem? NTFS is particular about this for most of the API calls using standard system settings. I think the maximum is 260 chars.

@diodiogod
Copy link
Contributor Author

Quick Q: does this (or the existing functionality) verify that the target folderpath/filename.ext length does not exceed the max pathlength for the filesystem? NTFS is particular about this for most of the API calls using standard system settings. I think the maximum is 260 chars.

I don't know If I have made any checks about maximum target path in this PR implementation. I would have to check.

@diodiogod
Copy link
Contributor Author

diodiogod commented Nov 5, 2025

Path Length Validation Implemented

@brendanhoar Thanks for raising this concern! I've added filesystem path length validation to address the NTFS 260-character limit issue.

What was implemented:

Backend:

  • Added validate_path_length() utility function in py/utils/utils.py
  • Integrated validation in ModelMoveService.move_model() - validates before attempting any move
  • Integrated validation in ModelFileService._process_single_model() - validates during auto-organize operations

Frontend:

  • Added client-side path length validation in MoveManager.validatePathLength()
  • Pre-flight validation in moveModel() before API call (both single and bulk moves)
  • Added user-friendly error message showing actual vs. allowed path length

How it works:

When a user attempts to move a model or use auto-organize, the system now:

  1. Calculates the final full path (root + relative path + filename)
  2. Checks if it exceeds 260 characters (Windows NTFS limit)
  3. If exceeded, shows a clear error message with the actual path length
  4. Prevents the move operation from being attempted

The validation is platform-aware (defaults to 260 for Windows NTFS, but can be adjusted for other filesystems).

Commit: b6feb3c

diodiogod pushed a commit to diodiogod/ComfyUI-Lora-Manager that referenced this pull request Nov 5, 2025
Adds validation to prevent filesystem path length limit violations (260 chars for Windows NTFS).
Validation is performed at three levels:
1. Backend utility function validate_path_length() in utils.py
2. Auto-organize operations in ModelFileService._process_single_model()
3. Individual model moves in ModelMoveService.move_model()
4. Frontend validation in MoveManager.moveModel() before API call

When path exceeds limit, users get clear error messages showing actual vs allowed length.

Addresses GitHub comment on PR willmiao#571 regarding filesystem constraints.
Adds validation to prevent filesystem path length limit violations (260 chars for Windows NTFS).
Validation is performed at three levels:
1. Backend utility function validate_path_length() in utils.py
2. Auto-organize operations in ModelFileService._process_single_model()
3. Individual model moves in ModelMoveService.move_model()
4. Frontend validation in MoveManager.moveModel() before API call

When path exceeds limit, users get clear error messages showing actual vs allowed length.

Addresses GitHub comment on PR willmiao#571 regarding filesystem constraints.
@diodiogod diodiogod force-pushed the feat/original-path-placeholder branch from 10d7eb7 to b6feb3c Compare November 5, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants