minor code improvememts
gammazero committed
Feb 12, 2021 at 14:13 UTC
515381da1286b967c2e1566a93f7c51b0699ebe2
3 files changed
+9
-15
repo/fsrepo/migrations/ipfsdir.go
+5
-10
@@ -16,6 +16,7 @@ import (
16
17
const (
18
envIpfsPath = "IPFS_PATH"
19
+ defIpfsDir = ".ipfs"
20
versionFile = "version"
21
22
// Local IPFS API
@@ -74,6 +75,9 @@ func ApiShell(ipfsDir string) (*api.Shell, string, error) {
75
// location in the home directory.
76
func IpfsDir(dir string) (string, error) {
77
var err error
78
+ if dir == "" {
79
+ dir = os.Getenv(envIpfsPath)
80
+ }
81
if dir != "" {
82
dir, err = homedir.Expand(dir)
83
if err != nil {
@@ -82,15 +86,6 @@ func IpfsDir(dir string) (string, error) {
86
return dir, nil
87
}
88
85
- ipfspath := os.Getenv(envIpfsPath)
86
- if ipfspath != "" {
87
- dir, err := homedir.Expand(ipfspath)
88
- if err != nil {
89
- return "", err
90
- }
91
- return dir, nil
92
- }
93
-
89
home, err := homedir.Dir()
90
if err != nil {
91
return "", err
@@ -99,7 +94,7 @@ func IpfsDir(dir string) (string, error) {
94
return "", errors.New("could not determine IPFS_PATH, home dir not set")
95
}
96
102
- return path.Join(home, ".ipfs"), nil
97
+ return path.Join(home, defIpfsDir), nil
98
}
99
100
// CheckIpfsDir gets the ipfs directory and checks that the directory exists.
repo/fsrepo/migrations/migrations.go
+2
-2
@@ -106,7 +106,7 @@ func migrationName(from, to int) string {
106
}
107
108
// findMigrations returns a list of migrations, ordered from first to last
109
-// migration to apply, and a map of locations migration binaries of any
109
+// migration to apply, and a map of locations of migration binaries of any
110
// migrations that were found.
111
func findMigrations(ctx context.Context, from, to int) ([]string, map[string]string, error) {
112
step := 1
@@ -155,7 +155,7 @@ func runMigration(ctx context.Context, binPath, ipfsDir string, revert bool) err
155
}
156
157
// fetchMigrations downloads the requested migrations, and returns a slice with
158
-// the paths of each binary, in the same order as in needed.
158
+// the paths of each binary, in the same order specified by needed.
159
func fetchMigrations(ctx context.Context, needed []string, destDir string) ([]string, error) {
160
osv, err := osWithVariant()
161
if err != nil {
repo/fsrepo/migrations/versions.go
+2
-3
@@ -54,9 +54,8 @@ func DistVersions(ctx context.Context, dist string, sortDesc bool) ([]string, er
54
}
55
vers = append(vers, ver)
56
}
57
- err = scan.Err()
58
- if err != nil {
59
- return nil, fmt.Errorf("could not read versions: %s", err)
57
+ if scan.Err() != nil {
58
+ return nil, fmt.Errorf("could not read versions: %s", scan.Err())
59
}
60
61
if sortDesc {