Fix long filename handling and separate character/byte truncation limits - #335
Open
LiuqingDu wants to merge 1 commit into
Open
Fix long filename handling and separate character/byte truncation limits#335LiuqingDu wants to merge 1 commit into
LiuqingDu wants to merge 1 commit into
Conversation
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.
Reopened from #324, rebased on the latest
mainto resolve conflicts with recent changes.Description
This PR fixes
OSError: [Errno 36] File name too longwhen generated output filenames exceed the filesystem byte limit.The issue is more likely with CJK titles because filename limits are byte-based, not character-based. For example:
The ASCII characters are mostly 1 byte each, while each Chinese character is usually 3 bytes in UTF-8. So a filename can be under 255 visible characters but still exceed the common 255-byte filename limit.
This is not limited to Chinese. Any filename containing many non-ASCII characters can hit this issue, including Japanese, Korean, emoji, and other writing systems. The filename may look shorter than 255 visible characters, but still exceed the filesystem's byte-based limit because UTF-8 encodes many of these characters as multiple bytes.
Changes
gamdl/downloader/base.py: Caps each generated path component at 255 UTF-8 bytes. Applies--truncateas a character limit first, then enforces the byte limit independently. Counts the file extension inside the filename byte budget.gamdl/cli/cli.py: Stops writing download entries to the database after unexpected download errors.gamdl/cli/database.py: Treats unstatable historical database paths as missing, so old bad entries do not crash future runs.