Skip to content

Commit c86ddfd

Browse files
authored
Merge pull request #240 from CortexFoundation/dev
torrent/client | path management of already existing ones
2 parents 3953e6b + 14d0cad commit c86ddfd

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

torrentfs/torrentClient.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,42 @@ func (tm *TorrentManager) listenTorrentProgress() {
827827

828828
if t.Finished() {
829829
tm.lock.Lock()
830-
err := os.Symlink(
831-
path.Join(defaultTmpFilePath, t.InfoHash()),
832-
path.Join(tm.DataDir, t.InfoHash()),
833-
)
830+
if _, err := os.Stat(path.Join(tm.DataDir, t.InfoHash())); err == nil {
831+
log.Debug("Path exist", "hash", t.Torrent.InfoHash(), "path", path.Join(tm.DataDir, t.InfoHash()))
832+
delete(tm.activeTorrents, ih)
833+
tm.seedingTorrents[ih] = t
834+
t.Seed()
835+
t.loop = defaultSeedInterval / queryTimeInterval
836+
total_size += uint64(t.bytesCompleted)
837+
current_size += uint64(t.bytesCompleted)
838+
} else {
839+
//log.Info("Path not exist", "hash", t.Torrent.InfoHash(), "path", path.Join(tm.DataDir, t.InfoHash()))
840+
err := os.Symlink(
841+
path.Join(defaultTmpFilePath, t.InfoHash()),
842+
path.Join(tm.DataDir, t.InfoHash()),
843+
)
834844

835-
if err != nil {
845+
if err != nil {
846+
//log.Warn("Seeding path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter)
847+
err = os.Remove(
848+
path.Join(tm.DataDir, t.InfoHash()),
849+
)
850+
if err != nil {
851+
// log.Warn("Fix path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter)
852+
} else {
853+
log.Debug("Fix path success", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter)
854+
}
855+
} else {
856+
delete(tm.activeTorrents, ih)
857+
tm.seedingTorrents[ih] = t
858+
t.Seed()
859+
t.loop = defaultSeedInterval / queryTimeInterval
860+
total_size += uint64(t.bytesCompleted)
861+
current_size += uint64(t.bytesCompleted)
862+
}
863+
}
864+
865+
/*if err != nil {
836866
//log.Warn("Seeding path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter)
837867
err = os.Remove(
838868
path.Join(tm.DataDir, t.InfoHash()),
@@ -849,7 +879,7 @@ func (tm *TorrentManager) listenTorrentProgress() {
849879
t.loop = defaultSeedInterval / queryTimeInterval
850880
total_size += uint64(t.bytesCompleted)
851881
current_size += uint64(t.bytesCompleted)
852-
}
882+
}*/
853883
tm.lock.Unlock()
854884
continue
855885
}

0 commit comments

Comments
 (0)