Skip to content

fix: skip re-import when the library file is already up to date - #29

Merged
eltharynd merged 3 commits into
eltharynd:mainfrom
nixypanda:nix-patches
Oct 17, 2026
Merged

eltharynd merged 3 commits into
eltharynd:mainfrom
nixypanda:nix-patches

Conversation

@nixypanda

@nixypanda nixypanda commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Importing a completed torrent is not idempotent: every pipeline run deletes the existing library file and re-links/copies it, which touches it and makes the media server rescan and regenerate trickplay/chapter images on each pass.

Fix

Short-circuit the delete+relink when the destination is already present:

  • hardlinks enabled → same hardlink (matching inode and device)
  • hardlinks disabled → identical-size copy

The file is still marked processed, so the torrent moves to the completed category as before.

Test

I added this test based on the structure I noticed in other places.

Adds src/torrent/torrent.controller.test.ts, which drives the real import path: an already-imported episode must not be re-created (ctime unchanged, metadata not re-updated). It fails on main before this change and passes after.

nixypanda and others added 3 commits October 15, 2026 16:41
Cover the re-import behaviour of a completed torrent: when the episode is
already present in the library as the same hardlink, importing again must not
recreate (touch) the library file.
Importing was not idempotent: every pipeline run unconditionally deleted and
recreated the library file, touching it and making the media server rescan and
regenerate trickplay/chapter images on each pass.

Skip the delete+relink when the destination is already the same hardlink
(matching inode and device), or an identical-size copy when hardlinks are
disabled, and mark the file processed so the torrent still moves on.
@eltharynd

Copy link
Copy Markdown
Owner

Good job.. it honestly wasn't a problem until I added alternative cuts.. but yeah I just added PIPELINE_FORCE_REIMPORT_EXISTING to force reimporting anyways (it's useful for currupted files, or for testing)

@eltharynd
eltharynd merged commit db4a1c6 into eltharynd:main Oct 17, 2026
3 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.

2 participants