Skip to content

Commit 917593b

Browse files
author
Andreas Auernhammer
committed
cli: create directories if they don't exist.
This commit fixes an issue when generating keys are signing a files with a custom signature file. Before, key generation resp. signing failed if the destination file would have been written to a directory that doesn't exist. Now, minisign will create any non-existing directory, if necessary.
1 parent fd48da6 commit 917593b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cmd/minisign/minisign.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ func generateKeyPair(secKeyFile, pubKeyFile string, force bool) {
134134
}
135135
}
136136

137+
if dir := filepath.Dir(secKeyFile); dir != "" && dir != "." && dir != "/" {
138+
if err := os.MkdirAll(dir, 0755); err != nil {
139+
log.Fatalf("Error: %v", err)
140+
}
141+
}
142+
if dir := filepath.Dir(pubKeyFile); dir != "" && dir != "." && dir != "/" {
143+
if err := os.MkdirAll(dir, 0755); err != nil {
144+
log.Fatalf("Error: %v", err)
145+
}
146+
}
147+
137148
fmt.Print("Please enter a password to protect the secret key.\n\n")
138149
var (
139150
password = readPassword(os.Stdin, "Enter Password: ")
@@ -218,6 +229,14 @@ func signFiles(secKeyFile, sigFile, untrustedComment, trustedComment string, pre
218229
}
219230
fmt.Print("done\n\n")
220231

232+
if sigFile != "" {
233+
if dir := filepath.Dir(sigFile); dir != "" && dir != "." && dir != "/" {
234+
if err := os.MkdirAll(dir, 0755); err != nil {
235+
log.Fatalf("Error: %v", err)
236+
}
237+
}
238+
}
239+
221240
for _, name := range files {
222241
var signature []byte
223242
file, err := os.Open(name)

0 commit comments

Comments
 (0)