Skip to content

Commit

Permalink
fix golang ci lint
Browse files Browse the repository at this point in the history
Signed-off-by: menyakun <lxs137@hotmail.com>
  • Loading branch information
lxs137 committed Jul 27, 2023
1 parent 3857fd3 commit d8b9611
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/image/filefmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// creates the destination file too large, by the difference between this const and 512.
const MaxExpectedHdrSize = 512

// CompressedFormat return whether file format is compressed
func CompressedFormat(format string) bool {
return format == "gz" || format == "xz" || format == "zst"
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/importer/format-readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type knownExtFileMatcher struct {
firstCalledFilepath *string
}

func NewKnownExtFileMatcher() *knownExtFileMatcher {
func newKnownExtFileMatcher() *knownExtFileMatcher {
return &knownExtFileMatcher{
calledFilepath: map[string]struct{}{},
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func (fr *FormatReaders) xzReader() (io.Reader, error) {
return xz, nil
}

func (fr *FormatReaders) AppendArchiveInnerFileReader(matcher util.FileMatcher) {
func (fr *FormatReaders) appendArchiveInnerFileReader(matcher util.FileMatcher) {
if !fr.ArchiveTar || fr.readers[len(fr.readers)-1].rdrType == rdrTar {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/importer/http-datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ func (hs *HTTPDataSource) Info() (ProcessingPhase, error) {
}
if hs.readers.ArchiveTar {
if hs.readers.Compressed {
hs.readers.AppendArchiveInnerFileReader(NewKnownExtFileMatcher())
hs.readers.appendArchiveInnerFileReader(newKnownExtFileMatcher())
// for unseekable compressed tar archive (gzip, xz with large block size),
// qemu-img over nbdkit will be super slow,
// so fallback to download to scratch
return ProcessingPhaseTransferScratch, nil
}
matcher := NewKnownExtFileMatcher()
matcher := newKnownExtFileMatcher()
innerFilepath, _, err := util.FindTarInnerFile(hs.readers.TopReader(), matcher)
if err != nil {
return ProcessingPhaseError, err
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func ResolveVolumeMode(volumeMode *v1.PersistentVolumeMode) v1.PersistentVolumeM
return retVolumeMode
}

// FileMatcher is a interface of file path matcher
type FileMatcher interface {
Match(filepath string) bool
}
Expand All @@ -476,13 +477,16 @@ type TarReader struct {
innerReader io.Reader
}

// NewTarReader construct TarReader
func NewTarReader(reader io.Reader, matcher FileMatcher) *TarReader {
return &TarReader{
Reader: reader,
InnerFileMatcher: matcher,
}
}

// Read reads bytes from the inner reader,
// the inner reader point to the tar inner file
func (r *TarReader) Read(p []byte) (n int, err error) {
if r.innerReader == nil {
_, innerReader, err := FindTarInnerFile(r.Reader, r.InnerFileMatcher)
Expand All @@ -496,7 +500,7 @@ func (r *TarReader) Read(p []byte) (n int, err error) {
return r.innerReader.Read(p)
}

// find the first file path and it's reader meet matcher in tar archive,
// FindTarInnerFile find the first file path and it's reader meet matcher in tar archive,
func FindTarInnerFile(reader io.Reader, matcher FileMatcher) (filepath string, innerFileReader io.Reader, err error) {
tarReader := tar.NewReader(reader)
for {
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/fileConversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func ArchiveFiles(targetFile, tgtDir string, sourceFilesNames ...string) (string
return tgtPath, nil
}

// ToGz create gzipped src file into tgtDir wit extension
func ToGz(src, tgtDir, ext string) (string, error) {
tgtFile, tgtPath, _ := createTargetFile(src, tgtDir, image.ExtGz)
defer tgtFile.Close()
Expand Down Expand Up @@ -137,6 +138,7 @@ func toZst(src, tgtDir, ext string) (string, error) {
return tgtPath, nil
}

// ToXz create xz src file into tgtDir wit extension
func ToXz(src, tgtDir, ext string) (string, error) {
tgtFile, tgtPath, _ := createTargetFile(src, tgtDir, image.ExtXz)
defer tgtFile.Close()
Expand Down

0 comments on commit d8b9611

Please sign in to comment.