Skip to content

Commit 51d0ae1

Browse files
committed
Code refactoring
1 parent 6540991 commit 51d0ae1

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

action/fs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ package action
99

1010
import (
1111
"bytes"
12+
"crypto/sha256"
1213
"fmt"
1314
"os"
1415
"path/filepath"
1516
"strconv"
1617
"strings"
1718

1819
"github.com/essentialkaos/ek/v13/fsutil"
19-
"github.com/essentialkaos/ek/v13/hash"
20+
"github.com/essentialkaos/ek/v13/hashutil"
2021
"github.com/essentialkaos/ek/v13/strutil"
2122
"github.com/essentialkaos/ek/v13/system"
2223

@@ -336,7 +337,7 @@ func Checksum(action *recipe.Action) error {
336337
return err
337338
}
338339

339-
fileHash := hash.FileHash(file)
340+
fileHash := hashutil.File(file, sha256.New())
340341

341342
switch {
342343
case !action.Negative && fileHash != mustHash:
@@ -368,7 +369,7 @@ func ChecksumRead(action *recipe.Action) error {
368369
return err
369370
}
370371

371-
hash := hash.FileHash(file)
372+
hash := hashutil.File(file, sha256.New())
372373

373374
return action.Command.Recipe.SetVariable(variable, hash)
374375
}

action/http.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,16 @@ func HTTPJSON(action *recipe.Action) error {
224224
}
225225

226226
querySlice := parseJSONQuery(query)
227-
jsonValue, _, _, err := jsonparser.Get(resp.Bytes(), querySlice...)
227+
jsonData, err := resp.Bytes()
228228

229229
if err != nil {
230-
return fmt.Errorf("Can't get JSON data: %v", err)
230+
return fmt.Errorf("Can't get response data: %w", err)
231+
}
232+
233+
jsonValue, _, _, err := jsonparser.Get(jsonData, querySlice...)
234+
235+
if err != nil {
236+
return fmt.Errorf("Can't get JSON data: %w", err)
231237
}
232238

233239
containsValue := string(jsonValue) == value

cli/barcode.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ package cli
88
// ////////////////////////////////////////////////////////////////////////////////// //
99

1010
import (
11+
"crypto/sha256"
1112
"fmt"
1213
"os/exec"
1314

1415
"github.com/essentialkaos/ek/v13/env"
1516
"github.com/essentialkaos/ek/v13/fmtutil/barcode"
16-
"github.com/essentialkaos/ek/v13/hash"
17+
"github.com/essentialkaos/ek/v13/hashutil"
1718

1819
"github.com/essentialkaos/bibop/recipe"
1920
)
@@ -28,7 +29,7 @@ func printBarcode(r *recipe.Recipe) {
2829
printErrorAndExit(err.Error())
2930
}
3031

31-
recipeCrc := hash.FileHash(r.File)
32+
recipeCrc := hashutil.File(r.File, sha256.New())
3233

3334
if err != nil {
3435
printErrorAndExit(err.Error())

0 commit comments

Comments
 (0)