From dcd7c8c65db4e52fb055302def5c5a2518e0c084 Mon Sep 17 00:00:00 2001 From: soup Date: Sat, 4 Jan 2025 13:37:07 +0100 Subject: [PATCH] fix(hardlink): skip incomplete torrents (#7) --- hardlinkfilemap/hardlinkfilemap.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hardlinkfilemap/hardlinkfilemap.go b/hardlinkfilemap/hardlinkfilemap.go index f1e063b..2068a30 100644 --- a/hardlinkfilemap/hardlinkfilemap.go +++ b/hardlinkfilemap/hardlinkfilemap.go @@ -51,6 +51,10 @@ func (t *HardlinkFileMap) linkInfoByPath(path string) (string, uint64, bool) { } func (t *HardlinkFileMap) AddByTorrent(torrent config.Torrent) { + if !torrent.Downloaded { + return + } + for _, f := range torrent.Files { f = t.considerPathMapping(f) @@ -72,6 +76,10 @@ func (t *HardlinkFileMap) AddByTorrent(torrent config.Torrent) { } func (t *HardlinkFileMap) RemoveByTorrent(torrent config.Torrent) { + if !torrent.Downloaded { + return + } + for _, f := range torrent.Files { f = t.considerPathMapping(f) @@ -111,6 +119,10 @@ func (t *HardlinkFileMap) countLinks(f string) (inmap uint64, total uint64, ok b } func (t *HardlinkFileMap) HardlinkedOutsideClient(torrent config.Torrent) bool { + if !torrent.Downloaded { + return false + } + for _, f := range torrent.Files { inmap, total, ok := t.countLinks(f) if !ok { @@ -126,6 +138,10 @@ func (t *HardlinkFileMap) HardlinkedOutsideClient(torrent config.Torrent) bool { } func (t *HardlinkFileMap) IsTorrentUnique(torrent config.Torrent) bool { + if !torrent.Downloaded { + return true + } + for _, f := range torrent.Files { c, _, ok := t.countLinks(f) if !ok { @@ -141,6 +157,10 @@ func (t *HardlinkFileMap) IsTorrentUnique(torrent config.Torrent) bool { } func (t *HardlinkFileMap) NoInstances(torrent config.Torrent) bool { + if !torrent.Downloaded { + return true + } + for _, f := range torrent.Files { c, _, ok := t.countLinks(f) if !ok {