From 14d0cadaa423d61872a72021374bd30b48fb90d6 Mon Sep 17 00:00:00 2001 From: ucwong Date: Tue, 19 Nov 2019 18:42:02 +0800 Subject: [PATCH] torrent/client | path management of already existing ones --- torrentfs/torrentClient.go | 42 ++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/torrentfs/torrentClient.go b/torrentfs/torrentClient.go index f885e4effd..22720caff8 100644 --- a/torrentfs/torrentClient.go +++ b/torrentfs/torrentClient.go @@ -827,12 +827,42 @@ func (tm *TorrentManager) listenTorrentProgress() { if t.Finished() { tm.lock.Lock() - err := os.Symlink( - path.Join(defaultTmpFilePath, t.InfoHash()), - path.Join(tm.DataDir, t.InfoHash()), - ) + if _, err := os.Stat(path.Join(tm.DataDir, t.InfoHash())); err == nil { + log.Debug("Path exist", "hash", t.Torrent.InfoHash(), "path", path.Join(tm.DataDir, t.InfoHash())) + delete(tm.activeTorrents, ih) + tm.seedingTorrents[ih] = t + t.Seed() + t.loop = defaultSeedInterval / queryTimeInterval + total_size += uint64(t.bytesCompleted) + current_size += uint64(t.bytesCompleted) + } else { + //log.Info("Path not exist", "hash", t.Torrent.InfoHash(), "path", path.Join(tm.DataDir, t.InfoHash())) + err := os.Symlink( + path.Join(defaultTmpFilePath, t.InfoHash()), + path.Join(tm.DataDir, t.InfoHash()), + ) - if err != nil { + if err != nil { + //log.Warn("Seeding path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter) + err = os.Remove( + path.Join(tm.DataDir, t.InfoHash()), + ) + if err != nil { + // log.Warn("Fix path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter) + } else { + log.Debug("Fix path success", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter) + } + } else { + delete(tm.activeTorrents, ih) + tm.seedingTorrents[ih] = t + t.Seed() + t.loop = defaultSeedInterval / queryTimeInterval + total_size += uint64(t.bytesCompleted) + current_size += uint64(t.bytesCompleted) + } + } + + /*if err != nil { //log.Warn("Seeding path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter) err = os.Remove( path.Join(tm.DataDir, t.InfoHash()), @@ -849,7 +879,7 @@ func (tm *TorrentManager) listenTorrentProgress() { t.loop = defaultSeedInterval / queryTimeInterval total_size += uint64(t.bytesCompleted) current_size += uint64(t.bytesCompleted) - } + }*/ tm.lock.Unlock() continue }