Skip to content
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

Rewrite operator_ui/install as go file #13169

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! Update operator_ui/install.go
  • Loading branch information
HenryNguyen5 committed Jun 12, 2024
commit 1cc8584cb3ac99981cdfc10cc6bd5b22bc4b734d
32 changes: 18 additions & 14 deletions operator_ui/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,24 @@ func decompressTgzSubpath(file io.Reader, destPath string, subPath string) error
}
fmt.Println("Creating directory", target)
case tar.TypeReg: // Regular file
// Wrap the file creation in a closure to ensure the file is closed even during a panic
return func() error {
f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
if err != nil {
return fmt.Errorf("failed to open file: %w", err)
}
defer f.Close()
/* #nosec G110 */
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
fmt.Println("Creating file", target)
return nil
}()
if err := writeFile(target, header, tr); err != nil {
return err
}
}
}
}

func writeFile(target string, header *tar.Header, tr *tar.Reader) error {
/* #nosec G110 */
f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
if err != nil {
return fmt.Errorf("failed to open file: %w", err)
}
defer f.Close()

if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
fmt.Println("Creating file", target)
return nil
}
Loading