Skip to content

Commit

Permalink
Merge pull request #1424 from facchettos/embedded-cp
Browse files Browse the repository at this point in the history
now cp doesn't read the whole file in memory
  • Loading branch information
FabianKramm authored Dec 21, 2023
2 parents efb0d05 + 89ff848 commit 0146623
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/util/cp/cp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cp

import "os"
import (
"io"
"os"
)

// this is a function that allows us to copy from
// distroless containers as they don't have the
Expand All @@ -10,9 +13,23 @@ func Cp(src, dest string) error {
if err != nil {
return err
}
bytes, err := os.ReadFile(src)
srcFile, err := os.Open(src)
if err != nil {
return err
}
return os.WriteFile(dest, bytes, info.Mode())
defer srcFile.Close()
destFile, err := os.Create(dest)
if err != nil {
return err
}
_, err = io.Copy(destFile, srcFile)
if err != nil {
return err
}
err = destFile.Close()
if err != nil {
return err
}

return os.Chmod(dest, info.Mode())
}

0 comments on commit 0146623

Please sign in to comment.