aboutsummaryrefslogtreecommitdiff
path: root/file/names.go
diff options
context:
space:
mode:
Diffstat (limited to 'file/names.go')
-rw-r--r--file/names.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/file/names.go b/file/names.go
index dd24617..7c714a8 100644
--- a/file/names.go
+++ b/file/names.go
@@ -2,6 +2,9 @@ package file
import (
"errors"
+ "os"
+ "os/user"
+ "path"
"path/filepath"
"strings"
)
@@ -34,7 +37,7 @@ func PubFile(comment string) (string, bool) {
if strings.HasPrefix(comment, verifyWith) {
file := comment[len(verifyWith):]
if strings.HasSuffix(file, ".pub") {
- return file, true
+ return FindFile(file), true
}
}
return "", false
@@ -43,3 +46,23 @@ func PubFile(comment string) (string, bool) {
func VerifyWith(encFile string) string {
return verifyWith + PubName(encFile)
}
+
+var safePath = []string{
+ "/etc/signify",
+ "~/.signify",
+ ".",
+}
+
+func FindFile(fname string) string {
+ usr, _ := user.Current()
+ for _, v := range safePath {
+ p := path.Join(v, fname)
+ if p[0] == '~' {
+ p = path.Join(usr.HomeDir, p[1:])
+ }
+ if _, err := os.Stat(p); err == nil {
+ return p
+ }
+ }
+ return fname
+}