-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch writefile to error when no content specified (#2388)
- Loading branch information
1 parent
8d9cfcd
commit 38b202a
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
projects/tinkerbell/hub/patches/0011-Ensure-content-is-specified-before-writing-file.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|