feat(sceneRename): rename via moveFiles and record original filename - #769
Merged
DogmaDragon merged 1 commit intoAug 31, 2026
Conversation
Renaming previously called os.rename() behind Stash's back and then kicked off metadata_scan() on the parent folder to repair the database. That left the file record pointing at a stale path until the scan finished, and the scan itself is a full job for what is a single-file change. Rename through the moveFiles mutation instead: Stash moves the file on disk and updates the file record in one transaction, so no rescan is needed. A destination folder is required even for an in-place rename, so the file's current parent_folder id is passed (falling back to its path). Also in this change: - Require a title, not just a studio. Without one the name collapsed to the studio plus resolution, which is less useful than the original filename. The README already documented this requirement; the code now matches it. The skip message names the missing field instead of listing every field. - Record the pre-rename basename in the scene's original_filename custom field, written once so the earliest known name survives later renames. A failed write is logged as a warning and does not fail the rename. - Harden filename sanitising. ":" is now stripped from studio names and codes, which never passed through clean_title(); control characters are collapsed to spaces; leading dots and trailing dots and spaces are trimmed. - Truncate to a byte budget rather than a character count. Filesystem name limits are in bytes (255 on ext4/btrfs), so a 240-character non-ASCII title could produce a name well over the limit and fail to rename. The budget also reserves room for the extension and a duplicate suffix. - Correct the README's filename format and worked example, which showed the resolution before the title while form_filename() emits it after.
|
This pull request has been mentioned on Stash Forum. There might be relevant details there: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SceneRename renamed files with
os.rename()behind Stash's back, then ranmetadata_scan()on the parent folder to repair the database afterwards. The file record pointed at a stale path until that scan completed, and a full folder scan is heavy for a single-file change.This switches the rename to the
moveFilesmutation, so Stash moves the file and updates the file record in one transaction and no rescan is needed. A destination folder is required even for an in-place rename, so the file's currentparent_folderid is passed, falling back to its path.Other changes
original_filenamecustom field, written once so the earliest known name survives later renames. A failed write logs a warning and does not fail the rename.:is now stripped from studio names and codes, which never passed throughclean_title(); control characters are collapsed to spaces; leading dots and trailing dots/spaces are trimmed.form_filename()emits it after.Version bumped to 1.2.0.
Testing
Run against a live Stash 0.31.1 library. Renames land through
moveFileswith no rescan and no stale paths;original_filenameis populated; scenes missing a title are skipped with the field named in the log. Sanitising was checked against studio/title combinations containing colons, newlines, tabs, NUL, leading dots and trailing dots/spaces, plus a 300-character CJK title, which previously produced a 706-byte name and now stays within the 255-byte limit.