Skip to content

Commit

Permalink
Patch writefile to error when no content specified (#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdoherty4 authored Aug 15, 2023
1 parent 8d9cfcd commit 38b202a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion projects/tinkerbell/hub/CHECKSUMS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
e004f52237340707b753fd226c6c369931d9d6c1f966615d6475d4c2fd13dcf0 _output/bin/hub/linux-amd64/image2disk
dcfec6b7c4fc2452defdaaec7a611fbe6cdf00e8e5dae86768447578849a4766 _output/bin/hub/linux-amd64/kexec
cdf00127e3c815c792e3eb7e61fa858095a62afb98bda2714f92e463ca95f0cb _output/bin/hub/linux-amd64/oci2disk
abd5d9e875dcebfed9948b49e74fbaeeb1c1a8385c5cf2c7ad1c05e5a48be239 _output/bin/hub/linux-amd64/writefile
9bbedaca313d22dd326665c84f308808bb73a593436d881b8929a887844b8ba6 _output/bin/hub/linux-amd64/writefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From 5c7b24fde808e5c175df6ff9f1286b49a0f156a9 Mon Sep 17 00:00:00 2001
From: Chris Doherty <[email protected]>
Date: Tue, 15 Aug 2023 13:34:34 -0500
Subject: [PATCH] Ensure content is specified before writing file

---
actions/writefile/v1/main.go | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/actions/writefile/v1/main.go b/actions/writefile/v1/main.go
index 954a45e..bf9f4ac 100644
--- a/actions/writefile/v1/main.go
+++ b/actions/writefile/v1/main.go
@@ -259,6 +259,10 @@ func main() {
}
}

+ if contents == "" {
+ log.Fatal("No content. Either the CONTENTS env var was not set or a data retrieval action failed.")
+ }
+
// If bootconfig is set, contents will be empty and will serve as output initrd file provided
// to bootconfig tool
fqFilePath := filepath.Join(mountAction, filePath)
@@ -292,7 +296,7 @@ func main() {
}

func appendToUserData(contents string, filePath string) error {
- f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+ f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
--
2.40.1

0 comments on commit 38b202a

Please sign in to comment.