fix LoadFromFile empty error (#8877)

This commit is contained in:
Alex Sharov 2023-12-01 18:50:06 +07:00 committed by GitHub
parent b5640bb64b
commit 421118378a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -485,11 +485,11 @@ func (d *Downloader) AddNewSeedableFile(ctx context.Context, name string) error
// if we don't have the torrent file we build it if we have the .seg file
torrentFilePath, err := BuildTorrentIfNeed(ctx, name, d.SnapDir())
if err != nil {
return err
return fmt.Errorf("AddNewSeedableFile: %w", err)
}
ts, err := loadTorrent(torrentFilePath)
if err != nil {
return err
return fmt.Errorf("AddNewSeedableFile: %w", err)
}
err = addTorrentFile(ctx, ts, d.torrentClient, d.webseeds)
if err != nil {

View File

@ -155,10 +155,10 @@ func BuildTorrentIfNeed(ctx context.Context, fName, root string) (torrentFilePat
fPath := filepath.Join(root, fName)
if dir2.FileExist(fPath + ".torrent") {
return
return fPath, nil
}
if !dir2.FileExist(fPath) {
return
return fPath, nil
}
info := &metainfo.Info{PieceLength: downloadercfg.DefaultPieceSize, Name: fName}
@ -281,9 +281,12 @@ func AllTorrentSpecs(dirs datadir.Dirs) (res []*torrent.TorrentSpec, err error)
return nil, err
}
for _, fPath := range files {
if len(fPath) == 0 {
continue
}
a, err := loadTorrent(fPath)
if err != nil {
return nil, err
return nil, fmt.Errorf("AllTorrentSpecs: %w", err)
}
res = append(res, a)
}