Skip to content

Commit 8960b3a

Browse files
committed
fix: don't encode bytes if we don't have to
1 parent b2a4905 commit 8960b3a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

peridot/cmd/v1/peridot/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pkg_rpm(
6565
license = "MIT",
6666
summary = "Peridot Command Line Interface",
6767
version = "0.2.1",
68-
release = "0",
68+
release = "1",
6969
architecture = "x86_64",
7070
description = "A command line interface to interact with the Peridot build system",
7171
source_date_epoch = 0,

peridot/cmd/v1/peridot/build_rpm_import.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
package main
3232

3333
import (
34+
"crypto/sha256"
3435
"encoding/base64"
36+
"encoding/hex"
3537
"log"
3638
"os"
3739
"strings"
3840
"time"
39-
"crypto/sha256"
40-
"encoding/hex"
41+
4142
"github.com/spf13/cobra"
4243
"openapi.peridot.resf.org/peridotopenapi"
4344
)
@@ -74,12 +75,12 @@ func isFile(path string) bool {
7475
return true
7576
}
7677

77-
func buildRpmImportMn(c *cobra.Command, args []string) {
78+
func buildRpmImportMn(_ *cobra.Command, args []string) {
7879
// Ensure project id exists
7980
projectId := mustGetProjectID()
8081

81-
var skipUpload bool = false
82-
var skipImport bool = false
82+
var skipUpload = false
83+
var skipImport = false
8384

8485
if skipStep != "" {
8586
switch strings.ToLower(skipStep) {
@@ -103,19 +104,22 @@ func buildRpmImportMn(c *cobra.Command, args []string) {
103104
var blobs []string
104105
projectCl := getClient(serviceProject).(peridotopenapi.ProjectServiceApi)
105106
for _, arg := range args {
107+
106108
bts, err := os.ReadFile(arg)
107109
errFatal(err)
108-
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
110+
109111
hash := sha256.Sum256(bts)
110112
shasum := hex.EncodeToString(hash[:])
111113

112114
if !skipUpload {
115+
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
113116
_, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
114117
File: &base64EncodedBytes,
115118
}).Execute()
116119
errFatal(err)
117120
log.Printf("Uploaded %s to lookaside", arg)
118121
}
122+
log.Printf("Will upload %s to lookaside for %s", shasum, arg)
119123
blobs = append(blobs, shasum)
120124
}
121125

0 commit comments

Comments
 (0)