in cli_tools/common/utils/storage/tar_gcs_extractor.go [43:92]
func (tge *TarGcsExtractor) ExtractTarToGcs(tarGcsPath string, destinationGcsPath string) error {
tarBucketName, tarPath, err := GetGCSObjectPathElements(tarGcsPath)
if err != nil {
return err
}
tarGcsReader, err := tge.storageClient.GetObject(tarBucketName, tarPath).NewReader()
if err != nil {
return daisy.Errf("error while opening archive %v: %v", tarGcsPath, err)
}
tarReader := tar.NewReader(tarGcsReader)
defer tarGcsReader.Close()
destinationBucketName, destinationPath, err := SplitGCSPath(destinationGcsPath)
if err != nil {
return daisy.Errf("invalid destination path: %v", destinationGcsPath)
}
for {
header, err := tarReader.Next()
switch {
// if no more files are found return
case err == io.EOF:
return nil
// return any other error
case err != nil:
return err
// if the header is nil, just skip it
case header == nil:
continue
}
switch header.Typeflag {
case tar.TypeDir:
return daisy.Errf("tar subdirectories not supported")
case tar.TypeReg:
destinationFilePath := path.Join(destinationPath, header.Name)
tge.logger.User(fmt.Sprintf("Extracting: %v to gs://%v", header.Name, path.Join(destinationBucketName, destinationFilePath)))
if err := tge.storageClient.WriteToGCS(destinationBucketName, destinationFilePath, tarReader); err != nil {
return err
}
}
}
}