Skip to content

Conversation

@snejus
Copy link
Member

@snejus snejus commented May 11, 2025

Description

This PR addresses an issue where path legalization, specifically the truncate_path function, incorrectly removed parts of filenames that followed a dot. This occurred because pathlib.Path.with_suffix was used, which replaces the existing suffix (or what it considers a suffix) rather than just appending.

The fix modifies truncate_path to manually append the original suffix after truncating the filename stem. This ensures that dots within the filename, not part of the actual extension, are preserved.

Fixes #5771.

  • Documentation. (If you've added a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

@snejus snejus requested review from Copilot, semohr and wisp3rwind May 11, 2025 00:44
@snejus snejus linked an issue May 11, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue in the path legalization function where the filename’s parts following the dot were being removed. The changes update the tests, modify truncate_path to manually append the suffix, and update the changelog for issue #5771.

  • Updated tests in test_util.py to clearly define scenarios with pytest.param.
  • Modified truncate_path in beets/util/init.py to concatenate the suffix after truncation.
  • Revised changelog documentation to reflect the fix.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/test_util.py Updated test parameters using pytest.param and removed duplicate variable.
docs/changelog.rst Documented the fix for the path suffix bug in the changelog.
beets/util/init.py Revised truncate_path to manually concatenate the suffix, preserving filename dots.

@snejus snejus changed the title Do not remove everything that follows a dot form destination paths Do not remove everything that follows a dot in item destination path May 11, 2025
@arogl
Copy link
Contributor

arogl commented May 11, 2025

Tested on a previous import and worked as expected. 👏

@snejus snejus force-pushed the 5771-beets-23-doesnt-like-dots-in-the-filename-patterns branch from 3eabe35 to f6e6d5e Compare May 11, 2025 11:09
@radusuciu
Copy link

This PR fixes the issue for me!

snejus added 2 commits May 12, 2025 09:14
TIL that `with_suffix` does not simply append the suffix to the filename
- it instead replaces the old/current suffix. Or whatever seems to
look like a suffix, in our case, unfortunately...
Also tighten `filetype` attribute type - empty value was previously
handled to accommodate a couple of tests, but they aren't failing
anymore, it seems.
@snejus snejus force-pushed the 5771-beets-23-doesnt-like-dots-in-the-filename-patterns branch from f6e6d5e to a4dabb6 Compare May 12, 2025 08:14
@snejus snejus enabled auto-merge May 12, 2025 08:15
@snejus snejus merged commit 0379f68 into master May 12, 2025
18 checks passed
@snejus snejus deleted the 5771-beets-23-doesnt-like-dots-in-the-filename-patterns branch May 12, 2025 08:23
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.

beets 2.3 doesn't like dots in the filename patterns

6 participants