When version file is missing, do not assume this indicates version 0 since that breaks tests that get the version to see if ipfs is initialized
gammazero committed
Jan 14, 2021 at 17:39 UTC
048db7599a9a498797a8f685739a880bc9f83e76
2 files changed
+5
-11
repo/fsrepo/migrations/ipfsdir.go
+1
-5
@@ -143,11 +143,7 @@ func WriteRepoVersion(ipfsDir string, version int) error {
143
func repoVersion(ipfsDir string) (int, error) {
144
c, err := ioutil.ReadFile(path.Join(ipfsDir, versionFile))
145
if err != nil {
146
- if os.IsNotExist(err) {
147
- // IPFS directory exists without version file, so version 0
148
- return 0, nil
149
- }
150
- return 0, fmt.Errorf("cannot read repo version file: %s", err)
146
+ return 0, err
147
}
148
149
ver, err := strconv.Atoi(strings.TrimSpace(string(c)))
repo/fsrepo/migrations/ipfsdir_test.go
+4
-6
@@ -73,12 +73,9 @@ func testCheckIpfsDir(t *testing.T) {
73
}
74
75
func testRepoVersion(t *testing.T) {
76
- ver, err := RepoVersion(fakeIpfs)
77
- if err != nil {
78
- t.Fatal(err)
79
- }
80
- if ver != 0 {
81
- t.Fatal("expected version 0 when no version file")
76
+ _, err := RepoVersion(fakeIpfs)
77
+ if !os.IsNotExist(err) {
78
+ t.Fatal("expected not-exist error")
79
}
80
81
testVer := 42
@@ -87,6 +84,7 @@ func testRepoVersion(t *testing.T) {
84
t.Fatal(err)
85
}
86
87
+ var ver int
88
ver, err = RepoVersion(fakeIpfs)
89
if err != nil {
90
t.Fatal(err)