+306
-92
lines changedFilter options
+306
-92
lines changed Original file line number Diff line number Diff line change
@@ -51,12 +51,12 @@ func computeChecksum(path string, h hash.Hash) (string, error) {
51
51
return string(h.Sum(nil)), nil
52
52
}
53
53
54
-
func checksumFile(path string, algo string) error {
54
+
func checksumFile(path string, algo string) (string, error) {
55
55
var h hash.Hash
56
56
57
57
switch algo {
58
58
case "none":
59
-
return nil
59
+
return "", nil
60
60
case "sha1":
61
61
h = sha1.New()
62
62
case "sha224":
@@ -68,19 +68,20 @@ func checksumFile(path string, algo string) error {
68
68
case "sha512":
69
69
h = sha512.New()
70
70
default:
71
-
return fmt.Errorf("unsupported hash algorithm: %s", algo)
71
+
return "", fmt.Errorf("unsupported hash algorithm: %s", algo)
72
72
}
73
73
74
74
i, err := os.Stat(path)
75
75
if err != nil {
76
-
return err
76
+
return "", err
77
77
}
78
78
79
-
l.Verbosef("create checksum file: %s.%s", path, algo)
80
-
o, err := os.Create(fmt.Sprintf("%s.%s", path, algo))
79
+
sumFile := fmt.Sprintf("%s.%s", path, algo)
80
+
l.Verbosef("create checksum file: %s", sumFile)
81
+
o, err := os.Create(sumFile)
81
82
if err != nil {
82
83
l.Errorln(err)
83
-
return err
84
+
return "", err
84
85
}
85
86
defer o.Close()
86
87
@@ -102,7 +103,7 @@ func checksumFile(path string, algo string) error {
102
103
})
103
104
104
105
if err != nil {
105
-
return fmt.Errorf("error walking the path %q: %v\n", path, err)
106
+
return "", fmt.Errorf("error walking the path %q: %v\n", path, err)
106
107
}
107
108
} else {
108
109
@@ -113,7 +114,7 @@ func checksumFile(path string, algo string) error {
113
114
r, _ := computeChecksum(path, h)
114
115
fmt.Fprintf(o, "%x %s\n", r, path)
115
116
}
116
-
return nil
117
+
return sumFile, nil
117
118
}
118
119
119
120
func checksumFileList(paths []string, algo string, sumFilePrefix string) error {
Original file line number Diff line number Diff line change
@@ -77,18 +77,18 @@ func TestChecksumFile(t *testing.T) {
77
77
}
78
78
79
79
// bad algo
80
-
if err := checksumFile("", "none"); err != nil {
80
+
if _, err := checksumFile("", "none"); err != nil {
81
81
t.Errorf("expected <nil>, got %q\n", err)
82
82
}
83
83
84
-
if err := checksumFile("", "other"); err == nil {
84
+
if _, err := checksumFile("", "other"); err == nil {
85
85
t.Errorf("expected err, got <nil>\n")
86
86
}
87
87
88
88
// test each algo with the file
89
89
for i, st := range tests {
90
90
t.Run(fmt.Sprintf("f%v", i), func(t *testing.T) {
91
-
if err := checksumFile("test", st.algo); err != nil {
91
+
if _, err := checksumFile("test", st.algo); err != nil {
92
92
t.Errorf("checksumFile returned: %v", err)
93
93
}
94
94
@@ -111,12 +111,12 @@ func TestChecksumFile(t *testing.T) {
111
111
// bad files
112
112
var e *os.PathError
113
113
l.logger.SetOutput(ioutil.Discard)
114
-
if err := checksumFile("", "sha1"); !errors.As(err, &e) {
114
+
if _, err := checksumFile("", "sha1"); !errors.As(err, &e) {
115
115
t.Errorf("expected an *os.PathError, got %q\n", err)
116
116
}
117
117
118
118
os.Chmod("test.sha1", 0444)
119
-
if err := checksumFile("test", "sha1"); !errors.As(err, &e) {
119
+
if _, err := checksumFile("test", "sha1"); !errors.As(err, &e) {
120
120
t.Errorf("expected an *os.PathError, got %q\n", err)
121
121
}
122
122
os.Chmod("test.sha1", 0644)
@@ -138,7 +138,7 @@ func TestChecksumFile(t *testing.T) {
138
138
// test each algo with the directory
139
139
for i, st := range tests {
140
140
t.Run(fmt.Sprintf("d%v", i), func(t *testing.T) {
141
-
if err := checksumFile("test.d", st.algo); err != nil {
141
+
if _, err := checksumFile("test.d", st.algo); err != nil {
142
142
t.Errorf("checksumFile returned: %v", err)
143
143
}
144
144
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4