mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 21:17:16 +00:00
565a4250d6
* save state * snapshot update works * save state * snapshot migrator * tx test * save state * migrations stages refactor * refactor snapshot migrator * compilation fixed * integrate snapshot migrator * goerli sync headers * debug async snapshotter on goerly * move verify headers, remove experiments, fix remove old snapshot * save state * refactor snapshotsync injection * fix deadlock * replace snapshot generation stage logic to migrate method * change done for body snapshot * clean * clean&&change deleted value * clean * fix hash len * fix hash len * remove one of wrap methods, add remove snapshots on start * add err check * fix shadowing * stages unwind order debug * matryoshka experiments * steam test * fix build * fix test * fix lint * fix test * fix test datarace * add get test * return timeout * fix mdbx overlap * fix after merge * change epoch size * clean todo * fix * return testdata * added return from sndownloader gorutine * fix review comments * Fix * More info Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
46 lines
999 B
Go
46 lines
999 B
Go
package snapshotsync
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
)
|
|
|
|
func BuildInfoBytesForSnapshot(root string, fileName string) (metainfo.Info, error) {
|
|
path := root + "/" + fileName
|
|
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
|
|
}
|