Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloader: atomic-fs to be less smart. if app called - Create() - don't check .lock. Otherwise can't create .torrent for existing .seg files. #10004

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading