Skip to content

Commit

Permalink
Merge pull request #240 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
torrent/client | path management of already existing ones
  • Loading branch information
ucwong authored Nov 19, 2019
2 parents 3953e6b + 14d0cad commit c86ddfd
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions torrentfs/torrentClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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
}
Expand Down

0 comments on commit c86ddfd

Please sign in to comment.