diff --git a/internal/outofband/download.go b/internal/download/download.go similarity index 93% rename from internal/outofband/download.go rename to internal/download/download.go index 18dbbd0c..dcac9fe9 100644 --- a/internal/outofband/download.go +++ b/internal/download/download.go @@ -1,4 +1,4 @@ -package outofband +package download import ( "bytes" @@ -24,8 +24,8 @@ var ( ErrFormat = errors.New("bad checksum format") ) -// download fetches the file into dst -func download(ctx context.Context, fileURL, dst string) error { +// FromURLToFile fetches the file into dst +func FromURLToFile(ctx context.Context, fileURL, dst string) error { // create file fileHandle, err := os.Create(dst) if err != nil { @@ -65,7 +65,7 @@ func download(ctx context.Context, fileURL, dst string) error { return err } -func checksumValidate(filename, checksum string) error { +func ChecksumValidate(filename, checksum string) error { // no checksum prefix, default to md5sum if !strings.Contains(checksum, ":") { return checksumValidateMD5(filename, checksum) diff --git a/internal/outofband/download_test.go b/internal/download/download_test.go similarity index 94% rename from internal/outofband/download_test.go rename to internal/download/download_test.go index ca0dff05..ad8f401c 100644 --- a/internal/outofband/download_test.go +++ b/internal/download/download_test.go @@ -1,4 +1,4 @@ -package outofband +package download import ( "os" @@ -57,7 +57,7 @@ func TestChecksumValidate(t *testing.T) { defer os.Remove(binPath) - err = checksumValidate(binPath, tt.checksum) + err = ChecksumValidate(binPath, tt.checksum) if tt.expectedError != nil { assert.ErrorIs(t, err, tt.expectedError) return diff --git a/internal/outofband/action_handlers.go b/internal/outofband/action_handlers.go index 3f495c86..6ee15f7e 100644 --- a/internal/outofband/action_handlers.go +++ b/internal/outofband/action_handlers.go @@ -11,6 +11,7 @@ import ( "github.com/bmc-toolbox/common" "github.com/hashicorp/go-multierror" "github.com/metal-toolbox/flasher/internal/device" + "github.com/metal-toolbox/flasher/internal/download" "github.com/metal-toolbox/flasher/internal/metrics" "github.com/metal-toolbox/flasher/internal/model" "github.com/pkg/errors" @@ -76,7 +77,6 @@ var ( ErrContextCancelled = errors.New("context canceled") ErrUnexpected = errors.New("unexpected error occurred") ErrInstalledFirmwareNotEqual = errors.New("installed and expected firmware not equal") - ErrInstalledFirmwareEqual = errors.New("installed and expected firmware are equal, no action necessary") ErrInstalledVersionUnknown = errors.New("installed version unknown") ErrComponentNotFound = errors.New("component not identified for firmware install") ErrRequireHostPoweredOff = errors.New("expected host to be powered off") @@ -284,7 +284,7 @@ func (h *handler) downloadFirmware(ctx context.Context) error { file := filepath.Join(dir, h.firmware.FileName) // download firmware file - err = download(ctx, h.firmware.URL, file) + err = download.FromURLToFile(ctx, h.firmware.URL, file) if err != nil { return err } @@ -301,7 +301,7 @@ func (h *handler) downloadFirmware(ctx context.Context) error { } // validate checksum - if err := checksumValidate(file, h.firmware.Checksum); err != nil { + if err := download.ChecksumValidate(file, h.firmware.Checksum); err != nil { os.RemoveAll(filepath.Dir(file)) return err }