fix: address review feedback regarding file closing and octal syntax

Signed-off-by: anushkagupta200615-jpg <anushkagupta200615@gmail.com>
pull/32347/head
anushkagupta200615-jpg 3 months ago
parent 8490fd28de
commit 05fd9c46ed

@ -209,24 +209,24 @@ func extractTarGz(r io.Reader, targetDir string) error {
return extractTar(gzr, targetDir)
}
// extractFile creates a single file from the tar archive
// extractFile creates a single file from the tar archive.
func extractFile(path string, mode int64, src io.Reader) error {
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0o755); err != nil {
return err
}
outFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, os.FileMode(mode))
outFile, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(mode))
if err != nil {
return err
}
defer outFile.Close()
if _, err := io.Copy(outFile, src); err != nil {
outFile.Close()
return err
}
return nil
return outFile.Close()
}
// extractTar extracts a tar archive to a directory

@ -56,7 +56,7 @@ func TestExtractTarFileDescriptorLeak(t *testing.T) {
for i := 0; i < 100; i++ {
hdr := &tar.Header{
Name: fmt.Sprintf("file_%d.txt", i),
Mode: 0600,
Mode: 0o600,
Size: 0,
Typeflag: tar.TypeReg,
}

Loading…
Cancel
Save