Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup image2disk package: #40

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions actions/image2disk/v1/pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"golang.org/x/sys/unix"
)

var tick chan time.Time

// WriteCounter counts the number of bytes written to it. It implements to the io.Writer interface
// and we can pass this into io.TeeReader() which will report progress on each write cycle.
type WriteCounter struct {
Expand Down Expand Up @@ -114,11 +112,6 @@ func UploadMultipartFile(client *http.Client, uri, key, path string, compressed
} else {
// With compression run data through gzip writer
zipWriter := gzip.NewWriter(w)
if err != nil {
errchan <- fmt.Errorf("[ERROR] New gzip reader: %s", err)
return
}

// run an io.Copy on the disk into the zipWriter
if written, err := io.Copy(zipWriter, diskIn); err != nil {
errchan <- fmt.Errorf("error copying %s (%d bytes written): %v", path, written, err)
Expand Down Expand Up @@ -209,19 +202,19 @@ func Write(sourceImage, destinationDevice string, compressed bool) error {
count, err := io.Copy(fileOut, out)
if err != nil {
ticker.Stop()
return fmt.Errorf("Error writing %d bytes to disk [%s] -> %v", count, destinationDevice, err)
return fmt.Errorf("error writing %d bytes to disk [%s] -> %v", count, destinationDevice, err)
}
fmt.Printf("\n")

ticker.Stop()

// Do the equivalent of partprobe on the device
if err := fileOut.Sync(); err != nil {
return fmt.Errorf("Failed to sync the block device")
return fmt.Errorf("failed to sync the block device")
}

if err := unix.IoctlSetInt(int(fileOut.Fd()), unix.BLKRRPART, 0); err != nil {
return fmt.Errorf("Error re-probing the partitions for the specified device")
return fmt.Errorf("error re-probing the partitions for the specified device: %v", err)
}

return nil
Expand Down