Skip to content

Commit

Permalink
cli: create directories if they don't exist.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andreas Auernhammer committed Mar 2, 2021
1 parent fd48da6 commit 917593b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/minisign/minisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ func generateKeyPair(secKeyFile, pubKeyFile string, force bool) {
}
}

if dir := filepath.Dir(secKeyFile); dir != "" && dir != "." && dir != "/" {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatalf("Error: %v", err)
}
}
if dir := filepath.Dir(pubKeyFile); dir != "" && dir != "." && dir != "/" {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatalf("Error: %v", err)
}
}

fmt.Print("Please enter a password to protect the secret key.\n\n")
var (
password = readPassword(os.Stdin, "Enter Password: ")
Expand Down Expand Up @@ -218,6 +229,14 @@ func signFiles(secKeyFile, sigFile, untrustedComment, trustedComment string, pre
}
fmt.Print("done\n\n")

if sigFile != "" {
if dir := filepath.Dir(sigFile); dir != "" && dir != "." && dir != "/" {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatalf("Error: %v", err)
}
}
}

for _, name := range files {
var signature []byte
file, err := os.Open(name)
Expand Down

0 comments on commit 917593b

Please sign in to comment.