@cryptotaxi247 / kubo / commits / 86c1fb8c9

msfr shouldn't swallow os.IsNotExist

- fsrepo calls and checks for this error (`fsrepo.go:140`) License: MIT Signed-off-by: Zander Mackie <zmackie@gmail.com>

Zander Mackie committed Jan 20, 2017 at 16:01 UTC 86c1fb8c965392e7a4ca872bd7b3750307b18925
2 files changed +9 -8
repo/fsrepo/migrations/mfsr.go
+2 -8
@@ -23,8 +23,8 @@ func (rp RepoPath) Version() (int, error) {
23 }
24
25 fn := rp.VersionFile()
26 - if _, err := os.Stat(fn); os.IsNotExist(err) {
27 - return 0, VersionFileNotFound(rp)
26 + if _, err := os.Stat(fn); err != nil {
27 + return 0, err
28 }
29
30 c, err := ioutil.ReadFile(fn)
@@ -53,9 +53,3 @@ func (rp RepoPath) WriteVersion(version int) error {
53 fn := rp.VersionFile()
54 return ioutil.WriteFile(fn, []byte(fmt.Sprintf("%d\n", version)), 0644)
55 }
56 -
57 -type VersionFileNotFound string
58 -
59 -func (v VersionFileNotFound) Error() string {
60 - return "no version file in repo at " + string(v)
61 -}
repo/fsrepo/migrations/mfsr_test.go
+7
@@ -2,6 +2,7 @@ package mfsr
2
3 import (
4 "io/ioutil"
5 + "os"
6 "testing"
7
8 "github.com/ipfs/go-ipfs/thirdparty/assert"
@@ -21,6 +22,12 @@ func TestVersion(t *testing.T) {
22 _, err := rp.Version()
23 assert.Err(err, t, "Should throw an error when path is bad,")
24
25 + rp = RepoPath("/path/to/nowhere")
26 + _, err = rp.Version()
27 + if !os.IsNotExist(err) {
28 + t.Fatalf("Should throw an `IsNotExist` error when file doesn't exist: %v", err)
29 + }
30 +
31 rp = testVersionFile("4", t)
32 _, err = rp.Version()
33 assert.Err(err, t, "Bad VersionFile")