Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed May 14, 2024
1 parent cead608 commit e0f08b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
16 changes: 16 additions & 0 deletions app/app_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ func (app *Application) WriteLine(format string, args ...any) (n int, err error)
return app.Write(format+"\n", args...)
}

func (app *Application) WriteVerbose(format string, args ...any) (n int, err error) {
if !app.Opts.Verbose {
return 0, nil
}

return fmt.Fprintf(app.Output, format, args...)
}

func (app *Application) WriteVerboseLine(format string, args ...any) (n int, err error) {
if !app.Opts.Verbose {
return 0, nil
}

return app.Write(format+"\n", args...)
}

func (app *Application) WriteError(format string, args ...any) {
fmt.Fprintf(app.Outputs.Stderr, format, args...)
}
Expand Down
18 changes: 12 additions & 6 deletions app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (app *Application) Run() *ReturnStatus {
app.VerifyChecksums(assetWrapper, body)

if app.Opts.Hash {
reporters.NewAssetSha256HashReporter(assetWrapper.Asset, app.Outputs.Stdout).Report(string(body))
reporters.NewAssetSha256HashReporter(assetWrapper.Asset, app.Output).Report(string(body))
}

tagDownloaded := utilities.SetIf(app.Opts.Tag != "", "latest", app.Opts.Tag)
Expand Down Expand Up @@ -219,7 +219,7 @@ func (app *Application) shouldReturn(err error) (bool, *ReturnStatus) {

// remote asset is not a newer version than the current version
if IsErrorOf(err, finders.ErrNoUpgrade) {
return true, NewReturnStatus(Success, nil, fmt.Sprintf("%s: %v", app.Target, err))
return true, NewReturnStatus(Success, finders.ErrNoUpgrade, fmt.Sprintf("%s: %v", app.Target, err))
}

// some other error occurred
Expand Down Expand Up @@ -442,13 +442,15 @@ func (app *Application) downloadAsset(asset *Asset, findResult *finders.FindResu

func (app *Application) VerifyChecksums(wrapper *AssetWrapper, body []byte) verifiers.VerifyChecksumResult {
verifier, sumAsset, err := app.getVerifier(*wrapper.Asset, wrapper.Assets)
needsNewLine := false

if verifier != nil && !utilities.SameImplementedInterface(verifier, verifiers.NoVerifier{}) {
if verifier != nil && verifier.String() != (verifiers.NoVerifier{}).String() {
app.Write("› performing verification for %s...", wrapper.Asset.Name)
needsNewLine = true
}

if err != nil {
app.WriteLine("Checksum verification failed, could not create a verifier.")
app.WriteLine("failed, could not create a verifier.")
return verifiers.VerifyChecksumFailedNoVerifier
}

Expand All @@ -467,6 +469,10 @@ func (app *Application) VerifyChecksums(wrapper *AssetWrapper, body []byte) veri
return verifiers.VerifyChecksumSuccess
}

if needsNewLine {
app.WriteLine("skipped")
}

return verifiers.VerifyChecksumNone
}

Expand Down Expand Up @@ -575,7 +581,7 @@ func (app *Application) getVerifier(asset Asset, assets []Asset) (verifier verif

for _, item := range assets {
if item.Name == asset.Name+".sha256sum" || item.Name == asset.Name+".sha256" {
app.WriteLine("verification against %s (%s)", item.Name, item.DownloadURL)
app.WriteVerboseLine("verification against %s (%s)", item.Name, item.DownloadURL)

verifier := verifiers.Sha256AssetVerifier{AssetURL: item.DownloadURL}
verifier.WithClient(app.DownloadClient())
Expand All @@ -588,7 +594,7 @@ func (app *Application) getVerifier(asset Asset, assets []Asset) (verifier verif
return nil, item, fmt.Errorf("extract binary name from asset url: %s: %w", asset, err)
}
binaryName := path.Base(binaryURL.Path)
app.WriteLine("› performing checksum verifications against %s (%s)", item.Name, item.DownloadURL)
app.WriteVerboseLine("› performing checksum verifications against %s (%s)", item.Name, item.DownloadURL)
return &verifiers.Sha256SumFileAssetVerifier{Sha256SumAssetURL: item.DownloadURL, BinaryName: binaryName, Client: download.NewClient("")}, item, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func GetCurrentDirectory() string {
}

// check if two interfaces implement the same type
func SameImplementedInterface(a, b interface{}) bool {
func SameImplementedInterface(a, b any) bool {
return reflect.TypeOf(a) == reflect.TypeOf(b)
}

Expand Down

0 comments on commit e0f08b5

Please sign in to comment.