From a0c652ecb8fb3dc092fc750ee3cb904903067f2d Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Wed, 28 Feb 2018 23:20:34 -0800 Subject: [PATCH] Make required directories on remote call --- cmd/pm/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/pm/main.go b/cmd/pm/main.go index 3e77309..5e380d1 100644 --- a/cmd/pm/main.go +++ b/cmd/pm/main.go @@ -4,7 +4,10 @@ import ( "bufio" "fmt" "os" + "path/filepath" + "github.com/pkg/errors" + "mcquay.me/fs" "mcquay.me/pm/keyring" "mcquay.me/pm/pkg" "mcquay.me/pm/remote" @@ -180,6 +183,10 @@ func main() { sub := os.Args[2] args := os.Args[3:] + if err := mkdirs(root); err != nil { + fatalf("making pm var directories: %v\n", err) + } + switch sub { case "add", "a": if len(args) < 1 { @@ -211,3 +218,13 @@ func fatalf(f string, args ...interface{}) { fmt.Fprintf(os.Stderr, f, args...) os.Exit(1) } + +func mkdirs(root string) error { + d := filepath.Join(root, "var", "lib", "pm") + if !fs.Exists(d) { + if err := os.MkdirAll(d, 0700); err != nil { + return errors.Wrap(err, "mk pm dir") + } + } + return nil +}