fix: Returned a file not found error on unity file reads

This commit is contained in:
Nicholas Novak 2023-12-13 23:33:10 -08:00
parent 5ad8bd2407
commit a2468a832f
2 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"io"
"io/fs"
"os"
"git.nicholasnovak.io/nnovak/spatial-db/world"
@ -115,7 +116,10 @@ func (u *UnityFile) ReadMetadataFile(fileName string) error {
}
func (u UnityFile) ReadChunk(pos world.ChunkPos) (world.ChunkData, error) {
m := u.metadata[pos]
m, contains := u.metadata[pos]
if !contains {
return world.ChunkData{}, fs.ErrNotExist
}
u.fd.Seek(int64(m.StartOffset), io.SeekStart)

View File

@ -2,7 +2,6 @@ package main
import (
"errors"
"io"
"testing"
"git.nicholasnovak.io/nnovak/spatial-db/storage"
@ -19,7 +18,7 @@ func readBlockTemplate(
for i := 0; i < b.N; i++ {
pos := world.RandomBlockPosWithRange(float64(pointSpread))
if _, err := storageServer.ReadBlockAt(pos); err != nil {
if errors.Is(err, storage.ChunkNotFoundError) || errors.Is(err, io.EOF) {
if errors.Is(err, storage.ChunkNotFoundError) {
continue
} else {
b.Error(err)