Commit 86c1fb8c authored by Zander Mackie's avatar Zander Mackie

msfr shouldn't swallow os.IsNotExist

- fsrepo calls and checks for this error (`fsrepo.go:140`)

License: MIT
Signed-off-by: default avatarZander Mackie <zmackie@gmail.com>
parent eb5ba9d7
......@@ -23,8 +23,8 @@ func (rp RepoPath) Version() (int, error) {
}
fn := rp.VersionFile()
if _, err := os.Stat(fn); os.IsNotExist(err) {
return 0, VersionFileNotFound(rp)
if _, err := os.Stat(fn); err != nil {
return 0, err
}
c, err := ioutil.ReadFile(fn)
......@@ -53,9 +53,3 @@ func (rp RepoPath) WriteVersion(version int) error {
fn := rp.VersionFile()
return ioutil.WriteFile(fn, []byte(fmt.Sprintf("%d\n", version)), 0644)
}
type VersionFileNotFound string
func (v VersionFileNotFound) Error() string {
return "no version file in repo at " + string(v)
}
......@@ -2,6 +2,7 @@ package mfsr
import (
"io/ioutil"
"os"
"testing"
"github.com/ipfs/go-ipfs/thirdparty/assert"
......@@ -21,6 +22,12 @@ func TestVersion(t *testing.T) {
_, err := rp.Version()
assert.Err(err, t, "Should throw an error when path is bad,")
rp = RepoPath("/path/to/nowhere")
_, err = rp.Version()
if !os.IsNotExist(err) {
t.Fatalf("Should throw an `IsNotExist` error when file doesn't exist: %v", err)
}
rp = testVersionFile("4", t)
_, err = rp.Version()
assert.Err(err, t, "Bad VersionFile")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment