Merge pull request #22055 from garthy/build_context_cleanup

Cleanup build scratch dir if remote end disconnects while passing the context
This commit is contained in:
openshift-merge-bot[bot] 2024-03-18 17:08:53 +00:00 committed by GitHub
commit 112aeb7fda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 10 deletions

View File

@ -50,7 +50,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
}
}
contextDirectory, err := extractTarFile(r)
anchorDir, err := os.MkdirTemp("", "libpod_builder")
if err != nil {
utils.InternalServerError(w, err)
return
@ -64,12 +64,18 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
}
}
}
err := os.RemoveAll(filepath.Dir(contextDirectory))
err := os.RemoveAll(anchorDir)
if err != nil {
logrus.Warn(fmt.Errorf("failed to remove build scratch directory %q: %w", filepath.Dir(contextDirectory), err))
logrus.Warn(fmt.Errorf("failed to remove build scratch directory %q: %w", anchorDir, err))
}
}()
contextDirectory, err := extractTarFile(anchorDir, r)
if err != nil {
utils.InternalServerError(w, err)
return
}
query := struct {
AddHosts string `schema:"extrahosts"`
AdditionalCapabilities string `schema:"addcaps"`
@ -884,13 +890,7 @@ func parseLibPodIsolation(isolation string) (buildah.Isolation, error) {
return parse.IsolationOption(isolation)
}
func extractTarFile(r *http.Request) (string, error) {
// build a home for the request body
anchorDir, err := os.MkdirTemp("", "libpod_builder")
if err != nil {
return "", err
}
func extractTarFile(anchorDir string, r *http.Request) (string, error) {
path := filepath.Join(anchorDir, "tarBall")
tarBall, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {