fix: Returned a file not found error on unity file reads
This commit is contained in:
parent
5ad8bd2407
commit
a2468a832f
@ -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)
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user