@cryptotaxi247 / kubo / commits / 5ee8710c5

feat: repo migrations - use filepath instead of path to support windows

Adin Schmahmann committed Mar 25, 2021 at 15:47 UTC 5ee8710c5806bb26982b82a1567a28c75d2aed05
6 files changed +23 -21
repo/fsrepo/migrations/fetch.go
+4 -4
@@ -9,7 +9,7 @@ import (
9 "io/ioutil"
10 "os"
11 "os/exec"
12 - "path"
12 + "path/filepath"
13 "runtime"
14 "strings"
15 )
@@ -29,7 +29,7 @@ import (
29 func FetchBinary(ctx context.Context, fetcher Fetcher, dist, ver, binName, out string) (string, error) {
30 // The archive file name is the base of dist. This is to support a possible subdir in
31 // dist, for example: "ipfs-repo-migrations/fs-repo-11-to-12"
32 - arcName := path.Base(dist)
32 + arcName := filepath.Base(dist)
33 // If binary base name is not specified, then it is same as archive base name.
34 if binName == "" {
35 binName = arcName
@@ -53,7 +53,7 @@ func FetchBinary(ctx context.Context, fetcher Fetcher, dist, ver, binName, out s
53 }
54 }
55 // out exists and is a directory, so compose final name
56 - out = path.Join(out, binName)
56 + out = filepath.Join(out, binName)
57 // Check if the binary already exists in the directory
58 _, err = os.Stat(out)
59 if !os.IsNotExist(err) {
@@ -83,7 +83,7 @@ func FetchBinary(ctx context.Context, fetcher Fetcher, dist, ver, binName, out s
83 arcDistPath, arcFullName := makeArchivePath(dist, arcName, ver, atype)
84
85 // Create a file to write the archive data to
86 - arcPath := path.Join(tmpDir, arcFullName)
86 + arcPath := filepath.Join(tmpDir, arcFullName)
87 arcFile, err := os.Create(arcPath)
88 if err != nil {
89 return "", err
repo/fsrepo/migrations/fetch_test.go
+2 -1
@@ -10,6 +10,7 @@ import (
10 "net/http/httptest"
11 "os"
12 "path"
13 + "path/filepath"
14 "runtime"
15 "strings"
16 "testing"
@@ -181,7 +182,7 @@ func TestFetchBinary(t *testing.T) {
182 t.Error("expected 'exists' error, got:", err)
183 }
184
184 - os.Remove(path.Join(tmpDir, ExeName("ipfs")))
185 + os.Remove(filepath.Join(tmpDir, ExeName("ipfs")))
186
187 // Check error creating temp download directory
188 //
repo/fsrepo/migrations/ipfsdir.go
+4 -4
@@ -5,7 +5,7 @@ import (
5 "fmt"
6 "io/ioutil"
7 "os"
8 - "path"
8 + "path/filepath"
9 "strconv"
10 "strings"
11
@@ -47,7 +47,7 @@ func IpfsDir(dir string) (string, error) {
47 return "", errors.New("could not determine IPFS_PATH, home dir not set")
48 }
49
50 - return path.Join(home, defIpfsDir), nil
50 + return filepath.Join(home, defIpfsDir), nil
51 }
52
53 // CheckIpfsDir gets the ipfs directory and checks that the directory exists.
@@ -84,12 +84,12 @@ func WriteRepoVersion(ipfsDir string, version int) error {
84 return err
85 }
86
87 - vFilePath := path.Join(ipfsDir, versionFile)
87 + vFilePath := filepath.Join(ipfsDir, versionFile)
88 return ioutil.WriteFile(vFilePath, []byte(fmt.Sprintf("%d\n", version)), 0644)
89 }
90
91 func repoVersion(ipfsDir string) (int, error) {
92 - c, err := ioutil.ReadFile(path.Join(ipfsDir, versionFile))
92 + c, err := ioutil.ReadFile(filepath.Join(ipfsDir, versionFile))
93 if err != nil {
94 return 0, err
95 }
repo/fsrepo/migrations/ipfsdir_test.go
+3 -3
@@ -3,7 +3,7 @@ package migrations
3 import (
4 "io/ioutil"
5 "os"
6 - "path"
6 + "path/filepath"
7 "testing"
8 )
9
@@ -21,7 +21,7 @@ func TestRepoDir(t *testing.T) {
21 defer os.RemoveAll(fakeHome)
22
23 os.Setenv("HOME", fakeHome)
24 - fakeIpfs = path.Join(fakeHome, ".ipfs")
24 + fakeIpfs = filepath.Join(fakeHome, ".ipfs")
25
26 t.Run("testIpfsDir", testIpfsDir)
27 t.Run("testCheckIpfsDir", testCheckIpfsDir)
@@ -144,7 +144,7 @@ func testRepoVersion(t *testing.T) {
144 if err != nil {
145 t.Fatal(err)
146 }
147 - vFilePath := path.Join(ipfsDir, versionFile)
147 + vFilePath := filepath.Join(ipfsDir, versionFile)
148 err = ioutil.WriteFile(vFilePath, []byte("bad-version-data\n"), 0644)
149 if err != nil {
150 panic(err)
repo/fsrepo/migrations/migrations_test.go
+3 -3
@@ -4,7 +4,7 @@ import (
4 "context"
5 "io/ioutil"
6 "os"
7 - "path"
7 + "path/filepath"
8 "strings"
9 "testing"
10 )
@@ -148,7 +148,7 @@ func TestRunMigrations(t *testing.T) {
148 defer os.RemoveAll(fakeHome)
149
150 os.Setenv("HOME", fakeHome)
151 - fakeIpfs := path.Join(fakeHome, ".ipfs")
151 + fakeIpfs := filepath.Join(fakeHome, ".ipfs")
152
153 err = os.Mkdir(fakeIpfs, os.ModePerm)
154 if err != nil {
@@ -184,7 +184,7 @@ func TestRunMigrations(t *testing.T) {
184 }
185
186 func createFakeBin(from, to int, tmpDir string) {
187 - migPath := path.Join(tmpDir, ExeName(migrationName(from, to)))
187 + migPath := filepath.Join(tmpDir, ExeName(migrationName(from, to)))
188 emptyFile, err := os.Create(migPath)
189 if err != nil {
190 panic(err)
repo/fsrepo/migrations/unpack_test.go
+7 -6
@@ -9,6 +9,7 @@ import (
9 "io/ioutil"
10 "os"
11 "path"
12 + "path/filepath"
13 "strings"
14 "testing"
15 )
@@ -38,7 +39,7 @@ func TestUnpackTgz(t *testing.T) {
39 }
40 defer os.RemoveAll(tmpDir)
41
41 - badTarGzip := path.Join(tmpDir, "bad.tar.gz")
42 + badTarGzip := filepath.Join(tmpDir, "bad.tar.gz")
43 err = ioutil.WriteFile(badTarGzip, []byte("bad-data\n"), 0644)
44 if err != nil {
45 panic(err)
@@ -48,14 +49,14 @@ func TestUnpackTgz(t *testing.T) {
49 t.Fatal("expected error opening gzip reader, got:", err)
50 }
51
51 - testTarGzip := path.Join(tmpDir, "test.tar.gz")
52 + testTarGzip := filepath.Join(tmpDir, "test.tar.gz")
53 testData := "some data"
54 err = writeTarGzipFile(testTarGzip, "testroot", "testfile", testData)
55 if err != nil {
56 panic(err)
57 }
58
58 - out := path.Join(tmpDir, "out.txt")
59 + out := filepath.Join(tmpDir, "out.txt")
60
61 // Test looking for file that is not in archive
62 err = unpackTgz(testTarGzip, "testroot", "abc", out)
@@ -86,7 +87,7 @@ func TestUnpackZip(t *testing.T) {
87 }
88 defer os.RemoveAll(tmpDir)
89
89 - badZip := path.Join(tmpDir, "bad.zip")
90 + badZip := filepath.Join(tmpDir, "bad.zip")
91 err = ioutil.WriteFile(badZip, []byte("bad-data\n"), 0644)
92 if err != nil {
93 panic(err)
@@ -96,14 +97,14 @@ func TestUnpackZip(t *testing.T) {
97 t.Fatal("expected error opening zip reader, got:", err)
98 }
99
99 - testZip := path.Join(tmpDir, "test.zip")
100 + testZip := filepath.Join(tmpDir, "test.zip")
101 testData := "some data"
102 err = writeZipFile(testZip, "testroot", "testfile", testData)
103 if err != nil {
104 panic(err)
105 }
106
106 - out := path.Join(tmpDir, "out.txt")
107 + out := filepath.Join(tmpDir, "out.txt")
108
109 // Test looking for file that is not in archive
110 err = unpackZip(testZip, "testroot", "abc", out)