From ae2b10d50da5455b382ab9d543be4fe859afe9e0 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Tue, 6 Sep 2016 01:56:41 +0200 Subject: storage: filesystem idx generation (wip) --- storage/filesystem/internal/index/index.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'storage/filesystem/internal/index/index.go') diff --git a/storage/filesystem/internal/index/index.go b/storage/filesystem/internal/index/index.go index 233dcbd..d33533e 100644 --- a/storage/filesystem/internal/index/index.go +++ b/storage/filesystem/internal/index/index.go @@ -34,50 +34,49 @@ func NewFromIdx(r io.Reader) (Index, error) { } // NewFrompackfile returns a new index from a packfile reader. -func NewFromPackfile(rs io.ReadSeeker) (Index, error) { +func NewFromPackfile(rs io.ReadSeeker) (Index, core.Hash, error) { s := packfile.NewSeekable(rs) return newFromPackfile(rs, s) } -func NewFromPackfileInMemory(rs io.Reader) (Index, error) { +func NewFromPackfileInMemory(rs io.Reader) (Index, core.Hash, error) { s := packfile.NewStream(rs) return newFromPackfile(rs, s) } -func newFromPackfile(r io.Reader, s packfile.ReadRecaller) (Index, error) { +func newFromPackfile(r io.Reader, s packfile.ReadRecaller) (Index, core.Hash, error) { index := make(Index) p := packfile.NewParser(s) count, err := p.ReadHeader() if err != nil { - return nil, err + return nil, core.ZeroHash, err } for i := 0; i < int(count); i++ { offset, err := s.Offset() if err != nil { - return nil, err + return nil, core.ZeroHash, err } obj := &core.MemoryObject{} if err := p.FillObject(obj); err != nil { - return nil, err + return nil, core.ZeroHash, err } err = s.Remember(offset, obj) if err != nil { - return nil, err + return nil, core.ZeroHash, err } if err = index.Set(obj.Hash(), offset); err != nil { - return nil, err + return nil, core.ZeroHash, err } } //The trailer records 20-byte SHA-1 checksum of all of the above. - p.ReadHash() - - return index, nil + hash, err := p.ReadHash() + return index, hash, err } // Get returns the offset that an object has the packfile. -- cgit