-
Notifications
You must be signed in to change notification settings - Fork 243
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
[WIP] bundle: Parallel download and decompression #4504
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
@@ -124,6 +125,36 @@ func (bundle *CrcBundleInfo) createSymlinkOrCopyPodmanRemote(binDir string) erro | |
return bundle.copyExecutableFromBundle(binDir, PodmanExecutable, constants.PodmanRemoteExecutableName) | ||
} | ||
|
||
func (repo *Repository) ExtractWithReader(ctx context.Context, reader io.Reader, path string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
logging.Debugf("Extracting bundle from reader") | ||
bundleName := filepath.Base(path) | ||
|
||
tmpDir := filepath.Join(repo.CacheDir, "tmp-extract") | ||
_ = os.RemoveAll(tmpDir) // clean up before using it | ||
defer func() { | ||
_ = os.RemoveAll(tmpDir) // clean up after using it | ||
}() | ||
|
||
if _, err := extract.UncompressWithReader(ctx, reader, tmpDir); err != nil { | ||
return err | ||
} | ||
|
||
bundleBaseDir := GetBundleNameWithoutExtension(bundleName) | ||
bundleDir := filepath.Join(repo.CacheDir, bundleBaseDir) | ||
_ = os.RemoveAll(bundleDir) | ||
err := crcerrors.Retry(context.Background(), time.Minute, func() error { | ||
if err := os.Rename(filepath.Join(tmpDir, bundleBaseDir), bundleDir); err != nil { | ||
return &crcerrors.RetriableError{Err: err} | ||
} | ||
return nil | ||
}, 5*time.Second) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return os.Chmod(bundleDir, 0755) | ||
} | ||
|
||
func (repo *Repository) Extract(ctx context.Context, path string) error { | ||
bundleName := filepath.Base(path) | ||
|
||
|
@@ -198,8 +229,15 @@ func Use(bundleName string) (*CrcBundleInfo, error) { | |
return defaultRepo.Use(bundleName) | ||
} | ||
|
||
func Extract(ctx context.Context, path string) (*CrcBundleInfo, error) { | ||
if err := defaultRepo.Extract(ctx, path); err != nil { | ||
func Extract(ctx context.Context, reader io.Reader, path string) (*CrcBundleInfo, error) { | ||
vyasgun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var err error | ||
if reader == nil { | ||
err = defaultRepo.Extract(ctx, path) | ||
} else { | ||
err = defaultRepo.ExtractWithReader(ctx, reader, path) | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return defaultRepo.Get(filepath.Base(path)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,13 +48,15 @@ func getCrcBundleInfo(ctx context.Context, preset crcPreset.Preset, bundleName, | |
return bundleInfo, nil | ||
} | ||
logging.Debugf("Failed to load bundle %s: %v", bundleName, err) | ||
|
||
logging.Infof("Downloading bundle: %s...", bundleName) | ||
bundlePath, err = bundle.Download(ctx, preset, bundlePath, enableBundleQuayFallback) | ||
reader, bundlePath, err := bundle.Download(ctx, preset, bundlePath, enableBundleQuayFallback) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
logging.Infof("Extracting bundle: %s...", bundleName) | ||
if _, err := bundle.Extract(ctx, bundlePath); err != nil { | ||
if _, err := bundle.Extract(ctx, reader, bundlePath); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a |
||
return nil, err | ||
} | ||
return bundle.Use(bundleName) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd add a
download.DownloadFile(…) (string, error)
to make it clear when we don't need the reader.