Make required directories on remote call

This commit is contained in:
Stephen McQuay 2018-02-28 23:20:34 -08:00
parent 28975b7890
commit a0c652ecb8
Signed by untrusted user: sm
GPG Key ID: 4E4B72F479BA3CE5

View File

@ -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
}