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" "bytes"
"encoding/json" "encoding/json"
"io" "io"
"io/fs"
"os" "os"
"git.nicholasnovak.io/nnovak/spatial-db/world" "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) { 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) u.fd.Seek(int64(m.StartOffset), io.SeekStart)

View File

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