diff --git a/code/go/0chain.net/blobbercore/filestore/storage.go b/code/go/0chain.net/blobbercore/filestore/storage.go index 74dcf531e..94a503f07 100644 --- a/code/go/0chain.net/blobbercore/filestore/storage.go +++ b/code/go/0chain.net/blobbercore/filestore/storage.go @@ -84,18 +84,19 @@ func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, i return nil, common.NewError("file_seek_error", err.Error()) } buf := make([]byte, BufferSize) - _, err = io.CopyBuffer(fileData.Hasher, infile, buf) + writtenSize, err := io.CopyBuffer(f, infile, buf) if err != nil { - return nil, common.NewError("file_read_error", err.Error()) + return nil, common.NewError("file_write_error", err.Error()) } - _, err = infile.Seek(0, io.SeekStart) + + _, err = f.Seek(fileData.UploadOffset, io.SeekStart) if err != nil { return nil, common.NewError("file_seek_error", err.Error()) } - writtenSize, err := io.CopyBuffer(f, infile, buf) + _, err = io.CopyBuffer(fileData.Hasher, f, buf) if err != nil { - return nil, common.NewError("file_write_error", err.Error()) + return nil, common.NewError("file_read_error", err.Error()) } finfo, err = f.Stat() diff --git a/code/go/0chain.net/blobbercore/filestore/tree_validation.go b/code/go/0chain.net/blobbercore/filestore/tree_validation.go index 2c60acaa9..b44145707 100644 --- a/code/go/0chain.net/blobbercore/filestore/tree_validation.go +++ b/code/go/0chain.net/blobbercore/filestore/tree_validation.go @@ -415,6 +415,10 @@ func GetNewCommitHasher(dataSize int64) *CommitHasher { } func (c *CommitHasher) Write(b []byte) (int, error) { + if !c.isInitialized || c.fmt == nil || c.vt == nil { + return 0, errors.New("commit hasher is not initialized") + } + var ( wg sync.WaitGroup errChan = make(chan error, 2)