summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-08-17 21:51:16 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-08-17 21:51:16 -0400
commite5735a08567e370b60cc1570f04f9a76019541f5 (patch)
tree8c20b8cbe5c6871797b78567ae19ff841770fb5d
parenta9e4d706c2e8d550e5b24549e16303e9b2507483 (diff)
Move default database file to ~/.config/shroud/db.gpg.
* shroud/utils.scm (mkdir-p): New procedure. * shroud/ui.scm (%default-config): Change default value of 'database-file'. (shroud-main): Ensure database directory has been created before saving.
-rw-r--r--shroud/ui.scm3
-rw-r--r--shroud/utils.scm29
2 files changed, 30 insertions, 2 deletions
diff --git a/shroud/ui.scm b/shroud/ui.scm
index 2fb3708..3cceac3 100644
--- a/shroud/ui.scm
+++ b/shroud/ui.scm
@@ -115,7 +115,7 @@ ARGS is the list of arguments received by the 'throw' handler."
(report-load-error file args))))
(define %default-config
- `((database-file . ,(string-append (getenv "HOME") "/.shroud-db"))
+ `((database-file . ,(string-append (getenv "HOME") "/.config/shroud/db.gpg"))
(gpg-binary . "gpg")))
(define (load-config)
@@ -175,4 +175,5 @@ ARGS is the list of arguments received by the 'throw' handler."
command)))
(apply proc config db args))))
(unless (eq? db result)
+ (mkdir-p (dirname db-file))
(save-secrets result db-file user-id))))))))
diff --git a/shroud/utils.scm b/shroud/utils.scm
index 59dbbc2..3f28840 100644
--- a/shroud/utils.scm
+++ b/shroud/utils.scm
@@ -27,7 +27,8 @@
alist-pick
gpg-binary
call-with-encrypted-output-file
- call-with-decrypted-input-file))
+ call-with-decrypted-input-file
+ mkdir-p))
(define (vhash-ref vhash key)
"Return the value associated with KEY in VHASH or #f if there is no
@@ -113,3 +114,29 @@ FILE."
"--no-tty" "--batch" "--yes"
"--decrypt" ,file)
proc)))))
+
+;; Written by Ludovic Courtès for GNU Guix.
+(define (mkdir-p dir)
+ "Create directory DIR and all its ancestors."
+ (define absolute?
+ (string-prefix? "/" dir))
+
+ (define not-slash
+ (char-set-complement (char-set #\/)))
+
+ (let loop ((components (string-tokenize dir not-slash))
+ (root (if absolute?
+ ""
+ ".")))
+ (match components
+ ((head tail ...)
+ (let ((path (string-append root "/" head)))
+ (catch 'system-error
+ (lambda ()
+ (mkdir path)
+ (loop tail path))
+ (lambda args
+ (if (= EEXIST (system-error-errno args))
+ (loop tail path)
+ (apply throw args))))))
+ (() #t))))