erigon-pulse/turbo/snapshotsync/build_infobytes.go
b00ris 57473175ff
Body snapshot (#2100)
* fix test

* get rid of ObjectDatabase

* sn_builder_prototype2

* save state

* save state

* integration step1

* fix lint

* fix

* fix test

* integrate migrator.finish

* fix lint

* fix build

* fix typo

* save state

* body snapshot test

* unique tx

* body snapshot generation using walk

* move methods out of test

* block data verification added

* fix lint

* test with remove works correctly

* fix lint

* remove experiment test

* fix test

* add comment

* add second layer of remove test

* rename test

* fix typos

* fix lint

* revert testdata

* body snapshot migration save state

* fix body snapshot migration

* fix after merge

* remove debug test

* debug windows build

* fix build

* fix

* fix lint

* debug

* fix

* fix windows build

* simplify snapshot management&&get rid of lazy tx

* fix lint

* fix windows path

* debug

* debug

* debug

* debug

* remove geometry experiments

* skip windows tests

* clean

* fix

* fix ;int
2021-07-06 23:33:26 +01:00

47 lines
1008 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 := filepath.Join(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
}