Skip to content

Commit

Permalink
fix(hardlink): skip incomplete torrents (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 authored Jan 4, 2025
1 parent 6dfa149 commit dcd7c8c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hardlinkfilemap/hardlinkfilemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit dcd7c8c

Please sign in to comment.