Skip to content

Commit

Permalink
torrent not found fix (#4101)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored May 8, 2022
1 parent 54076c9 commit 62fddbe
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmd/downloader/downloader/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,22 @@ func allSegmentFiles(dir string) ([]string, error) {
func BuildTorrentFileIfNeed(ctx context.Context, originalFileName, root string) (ok bool, err error) {
f, err := snap.ParseFileName(root, originalFileName)
if err != nil {
return false, err
return false, fmt.Errorf("ParseFileName: %w", err)
}
if f.To-f.From != snap.DEFAULT_SEGMENT_SIZE {
return false, nil
}
torrentFilePath := filepath.Join(root, originalFileName+".torrent")
if _, err := os.Stat(torrentFilePath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return false, err
return false, fmt.Errorf("os.Stat: %w", err)
}
info := &metainfo.Info{PieceLength: torrentcfg.DefaultPieceSize}
if err := info.BuildFromFilePath(filepath.Join(root, originalFileName)); err != nil {
return false, err
}
if err != nil {
return false, err
return false, fmt.Errorf("BuildFromFilePath: %w", err)
}
if err := CreateTorrentFile(root, info, nil); err != nil {
return false, err
return false, fmt.Errorf("CreateTorrentFile: %w", err)
}
}
return true, nil
Expand Down

0 comments on commit 62fddbe

Please sign in to comment.