fix: do not delete .mp3 file remuxed from MPEGLAYER3 WAV - #6874
Open
Sanjays2402 wants to merge 1 commit into
Open
fix: do not delete .mp3 file remuxed from MPEGLAYER3 WAV#6874Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
remux_mpeglayer3_wav() writes the extracted MP3 stream to
path.with_suffix('.mp3') and then removes the source. When the source
file is already named .mp3 (a WAVE_FORMAT_MPEGLAYER3 file with an mp3
extension), both paths are identical, so the freshly written file was
immediately deleted and the import silently lost the track.
Only remove the source when it is a distinct path from the remuxed
output. Adds a regression test covering the .mp3-named input.
Closes beetbox#6748
Contributor
There was a problem hiding this comment.
Pull request overview
PR fix nasty bug in importer remux path. when WAV-with-MP3-stream file already end in .mp3, code write new bytes then delete same file. PR make delete only happen when output path not same as input. also add regression test + changelog note.
Changes:
- Guard
util.remove()so remux-in-place (.mp3already) not delete output file - Add test case for MPEGLAYER3 WAV stored with
.mp3extension - Document fix in changelog (bug #6748)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| beets/util/extension.py | Avoid deleting remuxed output when input and output path are same |
| test/test_importer.py | Add regression test for .mp3-extension MPEGLAYER3 WAV case |
| docs/changelog.rst | Note bugfix in user-visible changelog |
Comment on lines
+173
to
+177
| # When the source is already named `.mp3`, it has just been rewritten in | ||
| # place with the extracted stream, so there is no separate original left | ||
| # to remove. | ||
| if mp3_path != syspath: | ||
| util.remove(path) |
Comment on lines
+1897
to
+1899
| def test_remux_mpeglayer3_wav_mp3_extension(self): | ||
| """A MPEGLAYER3 WAV named `.mp3` must not be deleted (#6748).""" | ||
| src = _common.RSRC / "mpeglayer3.wav" |
Comment on lines
+98
to
+100
| - ``remux_mp3_in_wav`` no longer deletes the imported file when a | ||
| MPEGLAYER3 WAV is named ``.mp3``: the remuxed stream was written back to the | ||
| same path and then removed as if it were a leftover original. :bug:`6748` |
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.
Description
Fixes #6748.
remux_mpeglayer3_wav()writes the extracted MP3 stream topath.with_suffix(".mp3")and then removes the source. When the source is already named.mp3(a WAVE_FORMAT_MPEGLAYER3 file with an mp3 extension, which is exactly the case reported), both paths are identical, so the file it just wrote was immediately deleted and the track was lost. The source is now only removed when it is a distinct path from the remuxed output.To Do
Documentation(no user-facing option changed)test_remux_mpeglayer3_wav_mp3_extensionfails on master with the file missing and passes with the fix.)