Skip to content

Remove archive on import during move mode#6551

Merged
snejus merged 8 commits intobeetbox:masterfrom
snystrom:master
Apr 19, 2026
Merged

Remove archive on import during move mode#6551
snejus merged 8 commits intobeetbox:masterfrom
snystrom:master

Conversation

@snystrom
Copy link
Copy Markdown
Contributor

Description

Fixes #1663.

This modifies the cleanup method on the ArchiveImportTask to remove the original archive file on successful import when move: yes.

I decided to do this such that partial imports do not destructively remove the archive. Perhaps this would be better as a configuration option, but I think that may go beyond the scope for this initial feature.

I am unsure whether my method for "complete import" is strictly correct, I reasoned that we would check that all files had been moved out, but surely this data exists more concretely somewhere. Let me know if this should be polished, or there's more nuance I'm not seeing!

Additionally, I added unit tests for this behavior under the old test framework since existing helpers are present for the archive backend setup. This way we minimize the diff and maximize probability that my test is behaving correctly. I will gladly port this entire archive test section to pytest in a future PR if this is a dealbreaker.

To Do

  • 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.)

This modifies the `cleanup` method on the `ArchiveImportTask` to remove the original archive file on successful import when `move: yes`.

I decided to do this such that partial imports do not destructively remove the archive. Perhaps this would be better as a configuration option, but I think that may go beyond the scope for this initial feature.

Additionally, I added unit tests for this behavior under the *old* test framework since existing helpers are present for the archive backend setup. This way we minimize the diff and maximize probability that my test is behaving correctly. I will gladly port this entire archive test section to pytest in a future PR.

Closes beetbox#1663.
Copilot AI review requested due to automatic review settings April 19, 2026 05:06
@snystrom snystrom requested a review from a team as a code owner April 19, 2026 05:06
Copy link
Copy Markdown
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

PR make archive import in move mode also remove original archive file, but only when import fully done (no files left in extracted temp dir). This address #1663.

Changes:

  • Track original archive path on ArchiveImportTask and delete it on successful move import.
  • Update changelog for new archive removal behavior.
  • Add unit tests to cover archive removal vs preserve cases and temp dir cleanup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
beets/importer/tasks.py Teach ArchiveImportTask.cleanup() to delete source archive when move and extracted dir empty.
test/test_importer.py Add tests for archive delete-on-move-complete and preserve-on-partial/copy, plus tempdir cleanup matrix.
docs/changelog.rst Document new behavior in Unreleased changelog.

Comment thread beets/importer/tasks.py Outdated
Comment thread docs/changelog.rst Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.85%. Comparing base (61a4ba9) to head (971de16).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
beets/importer/tasks.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6551   +/-   ##
=======================================
  Coverage   71.84%   71.85%           
=======================================
  Files         156      156           
  Lines       20173    20181    +8     
  Branches     3209     3211    +2     
=======================================
+ Hits        14494    14501    +7     
- Misses       5000     5001    +1     
  Partials      679      679           
Files with missing lines Coverage Δ
beets/importer/tasks.py 90.74% <80.00%> (-0.05%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snystrom
Copy link
Copy Markdown
Contributor Author

Not really sure it's worth the squeeze to add a test for the uncovered lines, really just a fallback for if we haven't extracted by the time we hit cleanup.... should that ever happen (if not, should I just error?)

Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

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

Looks good - just a small comment regarding docstring conventions.

Comment thread beets/importer/tasks.py Outdated
Comment thread beets/importer/tasks.py Outdated
Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

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

Now just move the changelog note under the Unreleased section since we pushed a new release earlier today.

@snejus snejus enabled auto-merge April 19, 2026 20:06
auto-merge was automatically disabled April 19, 2026 21:11

Head branch was pushed to by a user without write access

@snystrom
Copy link
Copy Markdown
Contributor Author

Hah, nice. Here ya go!

@snystrom
Copy link
Copy Markdown
Contributor Author

oh gah my bad, messed it up

Comment thread docs/changelog.rst Outdated
@snejus snejus merged commit 44ffbdf into beetbox:master Apr 19, 2026
18 checks passed
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.

Option for moving original archive (zip, rar) to trash after successful import

3 participants