Skip to content

Commit

Permalink
Downloader: atomic-fs to be less smart. if app called - Create() - do…
Browse files Browse the repository at this point in the history
…n't check .lock. Otherwise can't create .torrent for existing .seg files. (erigontech#10004)
  • Loading branch information
AskAlexSharov authored Apr 22, 2024
1 parent 596d54d commit 3f7cf91
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,6 @@ func (d *Downloader) AddMagnetLink(ctx context.Context, infoHash metainfo.Hash,
}

t, ok, err := addTorrentFile(ctx, spec, d.torrentClient, d.db, d.webseeds)

if err != nil {
return err
}
Expand Down
21 changes: 5 additions & 16 deletions erigon-lib/downloader/torrent_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,22 @@ func (tf *AtomicTorrentFS) delete(name string) error {
return os.Remove(filepath.Join(tf.dir, name))
}

func (tf *AtomicTorrentFS) Create(name string, res []byte) (ts *torrent.TorrentSpec, prohibited, created bool, err error) {
func (tf *AtomicTorrentFS) Create(name string, res []byte) (ts *torrent.TorrentSpec, created bool, err error) {
tf.lock.Lock()
defer tf.lock.Unlock()
prohibited, err = tf.newDownloadsAreProhibited(name)
if err != nil {
return nil, false, false, err
}

if !tf.exists(name) && !prohibited {
if !tf.exists(name) {
err = tf.create(name, res)
if err != nil {
return nil, false, false, err
return nil, false, err
}
}

ts, err = tf.load(filepath.Join(tf.dir, name))
if err != nil {
return nil, false, false, err
return nil, false, err
}
return ts, prohibited, false, nil
return ts, false, nil
}

func (tf *AtomicTorrentFS) create(name string, res []byte) error {
Expand Down Expand Up @@ -136,13 +132,6 @@ func (tf *AtomicTorrentFS) CreateWithMetaInfo(info *metainfo.Info, additionalMet
tf.lock.Lock()
defer tf.lock.Unlock()

prohibited, err := tf.newDownloadsAreProhibited(name)
if err != nil {
return false, err
}
if prohibited {
return false, nil
}
if tf.exists(name) {
return false, nil
}
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/downloader/webseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func (d *WebSeeds) DownloadAndSaveTorrentFile(ctx context.Context, name string)
d.logger.Log(d.verbosity, "[snapshots] .torrent from webseed rejected", "name", name, "err", err)
continue // it's ok if some HTTP provider failed - try next one
}
ts, _, _, err = d.torrentFiles.Create(name, res)
ts, _, err = d.torrentFiles.Create(name, res)
return ts, ts != nil, err
}

Expand Down

0 comments on commit 3f7cf91

Please sign in to comment.