mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
6464da7670
* save state * save state * save state * refactoring * fix * save state * save state * fmt * fix lint * restore torrents for external downloader * fix lint * download * skip debug test * debug * remote debug * small cli fixes * skip debug test * external snapshot predownloader * get rid of remote downloader * fix lint * clean makefile * fix lint * fix lint * cleanup * fix ci * fmt * remove proto from interfaces * Squashed 'interfaces/' content from commit acd02bb94 git-subtree-dir: interfaces git-subtree-split: acd02bb94c5a421aa8f8d1fd76cd8aad668e9fcb
46 lines
988 B
Go
46 lines
988 B
Go
package bittorrent
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
)
|
|
|
|
func BuildInfoBytesForLMDBSnapshot(root string) (metainfo.Info, error) {
|
|
path := root + "/" + LmdbFilename
|
|
fi, err := os.Stat(path)
|
|
if err != nil {
|
|
return metainfo.Info{}, err
|
|
}
|
|
relPath, err := filepath.Rel(root, path)
|
|
if err != nil {
|
|
return metainfo.Info{}, fmt.Errorf("error getting relative path: %s", err)
|
|
}
|
|
|
|
info := metainfo.Info{
|
|
Name: filepath.Base(root),
|
|
PieceLength: DefaultChunkSize,
|
|
Length: fi.Size(),
|
|
Files: []metainfo.FileInfo{
|
|
{
|
|
Length: fi.Size(),
|
|
Path: []string{relPath},
|
|
PathUTF8: nil,
|
|
},
|
|
},
|
|
}
|
|
|
|
err = info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
|
|
return os.Open(filepath.Join(root, strings.Join(fi.Path, string(filepath.Separator))))
|
|
})
|
|
if err != nil {
|
|
err = fmt.Errorf("error generating pieces: %s", err)
|
|
return metainfo.Info{}, err
|
|
}
|
|
return info, nil
|
|
}
|