From 917593ba15aafc778fd4bf9ded9dd13f4a974fad Mon Sep 17 00:00:00 2001 From: Andreas Auernhammer Date: Wed, 3 Mar 2021 00:46:34 +0100 Subject: [PATCH] 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. --- cmd/minisign/minisign.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/minisign/minisign.go b/cmd/minisign/minisign.go index 02afba2..4784964 100644 --- a/cmd/minisign/minisign.go +++ b/cmd/minisign/minisign.go @@ -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: ") @@ -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)