Skip to content

Fix purge_nonexistent_images.bat to correctly handle images which have cyrillic (or other alphabets) in the path#20916

Open
mishavoloshchuk wants to merge 2 commits into
darktable-org:masterfrom
mishavoloshchuk:fix/purge_nonexistent_images_removing_images
Open

Fix purge_nonexistent_images.bat to correctly handle images which have cyrillic (or other alphabets) in the path#20916
mishavoloshchuk wants to merge 2 commits into
darktable-org:masterfrom
mishavoloshchuk:fix/purge_nonexistent_images_removing_images

Conversation

@mishavoloshchuk

Copy link
Copy Markdown

I've made a fix for the purge_nonexistent_images.bat removes existing files / #20915 issue I recently added. I used Claude, because I'm not very proficient in .bat scripts. I've checked it and works completely fine and now it only removes the images that are really missing.

Screenshot 2026-05-02 172152 Screenshot 2026-05-02 172311 Screenshot 2026-05-02 172352

Here is some description from Claude itself:

The script uses for /f ... in ('sqlite3.exe ...') to iterate over query results. On Windows, this form of command substitution captures the child process output through the legacy OEM code page (e.g. CP866 for Russian locales), regardless of the active console code page set by chcp. SQLite3 outputs UTF-8 text, but for /f re-encodes it through the OEM code page, mangling any characters outside the ASCII range. The resulting garbled path string never matches a real filesystem entry, so if not exist always evaluates to true — and the image is treated as missing and scheduled for deletion, even though the underlying file is perfectly intact.

@TurboGit TurboGit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok by me but I'd like the review of a Windows expert;

@wpferguson : Can you review please? TIA

@TurboGit TurboGit added this to the 5.6 milestone May 3, 2026
@TurboGit TurboGit added the scope: windows support windows related issues and PR label May 3, 2026
@wpferguson

Copy link
Copy Markdown
Member

@victoryforce are you able to test this?

@andriiryzhkov

Copy link
Copy Markdown
Collaborator

@mishavoloshchuk : Nice fix – verified the temp-file workaround and the %ids%!ids! correction are both needed.

One optional polish from #21245: save and restore the original codepage around the section that needs UTF-8, rather than leaving the user's console at chcp 65001 after the script exits.

for /f "tokens=4" %%a in ('chcp') do set "OLD_CP=%%a"
chcp 65001 >nul
:: ... loop using the temp file ...
chcp %OLD_CP% >nul

Not blocking – the current approach works correctly. Only matters if someone calls this script from another batch file that expects a specific codepage afterwards, which is unlikely for a maintenance tool. Up to you.

@mishavoloshchuk

mishavoloshchuk commented Jun 9, 2026

Copy link
Copy Markdown
Author

@andriiryzhkov Thanks for the suggestion! Implemented it in the last commit. I also verified that the script still works correctly after that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: windows support windows related issues and PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants