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

Support raw.tar.gz files #2822

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 17 additions & 0 deletions pkg/importer/format-readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package importer

import (
"archive/tar"
"bytes"
"compress/gzip"
"encoding/hex"
Expand Down Expand Up @@ -163,6 +164,11 @@ func (fr *FormatReaders) fileFormatSelector(hdr *image.Header) {
var err error
fFmt := hdr.Format
switch fFmt {
case "tar":
r, err = fr.tarReader()
if err == nil {
fr.Archived = true
}
case "gz":
r, err = fr.gzReader()
if err == nil {
Expand Down Expand Up @@ -227,6 +233,17 @@ func (fr *FormatReaders) zstReader() (io.ReadCloser, error) {
return zst.IOReadCloser(), nil
}

func (fr *FormatReaders) tarReader() (io.ReadCloser, error) {
tr := tar.NewReader(fr.TopReader())

hdr, err := tr.Next() // advance cursor to 1st (and only) file in tarball
if err != nil {
return nil, errors.Wrap(err, "could not read tar header")
}
klog.V(2).Infof("tar: extracting %q\n", hdr.Name)
return io.NopCloser(tr), nil
}

// Return the size of the endpoint "through the eye" of the previous reader. Note: there is no
// qcow2 reader so nil is returned so that nothing is appended to the reader stack.
// Note: size is stored at offset 24 in the qcow2 header.
Expand Down