remove temporary files when copy

[NO NEW TESTS NEEDED]

Fixes: #19496

Signed-off-by: binghongtao <695097494plus@gmail.com>
This commit is contained in:
binghongtao
2023-08-06 22:38:08 +08:00
parent eceae9da57
commit 23c5890f25

View File

@ -382,6 +382,8 @@ func copyToContainer(container string, containerPath string, hostPath string) er
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(tmpFile.Name())
_, err = io.Copy(tmpFile, os.Stdin) _, err = io.Copy(tmpFile, os.Stdin)
if err != nil { if err != nil {
return err return err
@ -389,6 +391,7 @@ func copyToContainer(container string, containerPath string, hostPath string) er
if err = tmpFile.Close(); err != nil { if err = tmpFile.Close(); err != nil {
return err return err
} }
if !archive.IsArchivePath(tmpFile.Name()) { if !archive.IsArchivePath(tmpFile.Name()) {
return errors.New("source must be a (compressed) tar archive when copying from stdin") return errors.New("source must be a (compressed) tar archive when copying from stdin")
} }