mirror of https://github.com/perkeep/perkeep.git
fs: don't cause io errors on missing blobrefs
- Looking up missing blobrefs would cause fs errors. Instead, simply return fuse.ENOENT. - Add tests for: * validating that the mountpoint/<blobref> lookups work * validating that the mountpount/<blobref> lookups don't fail when the blob does not exist.
This commit is contained in:
parent
7eee938ddf
commit
317e9f5490
|
@ -90,6 +90,7 @@ type mountEnv struct {
|
|||
t *testing.T
|
||||
mountPoint string
|
||||
process *os.Process
|
||||
world *test.World
|
||||
}
|
||||
|
||||
func (e *mountEnv) Stat(s *stat) int64 {
|
||||
|
@ -200,6 +201,7 @@ func pkmountTest(t *testing.T, fn func(env *mountEnv)) {
|
|||
t: t,
|
||||
mountPoint: mountPoint,
|
||||
process: mount.Process,
|
||||
world: w,
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -224,6 +226,33 @@ func TestRoot(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestReadFileFromRoot(t *testing.T) {
|
||||
condSkip(t)
|
||||
pkmountTest(t, func(env *mountEnv) {
|
||||
// pk-put a file
|
||||
tmpFile, err := ioutil.TempFile(t.TempDir(), "camlitest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testContent := "some test content"
|
||||
tmpFile.WriteString(testContent)
|
||||
blobRef := env.world.PutFile(t, tmpFile.Name())
|
||||
|
||||
// Read it using the file's blobref
|
||||
if contents, err := ioutil.ReadFile(filepath.Join(env.mountPoint, blobRef.String())); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if got := string(contents); got != testContent {
|
||||
t.Fatalf("Expected test content, got %q", got)
|
||||
}
|
||||
|
||||
// Read a non-existing blobref, should return NotExist.
|
||||
badRefPath := filepath.Join(env.mountPoint, "sha224-1853501438ffe541dd1e48b9efc4a230f67f7b98afe83df24bfbfa25")
|
||||
if _, err := os.Stat(badRefPath); !os.IsNotExist(err) {
|
||||
t.Fatalf("expected NotExist; got stat err = %v instead", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type testLog struct {
|
||||
t *testing.T
|
||||
}
|
||||
|
|
|
@ -135,7 +135,11 @@ func (n *root) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
|||
|
||||
if br, ok := blob.Parse(name); ok {
|
||||
Logger.Printf("Root lookup of blobref. %q => %v", name, br)
|
||||
return &node{fs: n.fs, blobref: br}, nil
|
||||
node := &node{fs: n.fs, blobref: br}
|
||||
if _, err := node.schema(); os.IsNotExist(err) {
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
return node, nil
|
||||
}
|
||||
Logger.Printf("Bogus root lookup of %q", name)
|
||||
return nil, fuse.ENOENT
|
||||
|
|
|
@ -311,6 +311,15 @@ func (w *World) NewPermanode(t *testing.T) blob.Ref {
|
|||
return br
|
||||
}
|
||||
|
||||
func (w *World) PutFile(t *testing.T, name string) blob.Ref {
|
||||
out := MustRunCmd(t, w.Cmd("pk-put", "file", name))
|
||||
br, ok := blob.Parse(strings.TrimSpace(out))
|
||||
if !ok {
|
||||
t.Fatalf("Expected blobref in pk-put stdout; got %q", out)
|
||||
}
|
||||
return br
|
||||
}
|
||||
|
||||
func (w *World) Cmd(binary string, args ...string) *exec.Cmd {
|
||||
return w.CmdWithEnv(binary, os.Environ(), args...)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue