git » chasquid » commit 7b51ce7

chasquid: Ignore non-directories in certs/

author Alberto Bertogli
2016-11-22 20:39:19 UTC
committer Alberto Bertogli
2016-11-22 20:39:19 UTC
parent 170aaaf490e47341a0bae7e8cb39fbb38fde5247

chasquid: Ignore non-directories in certs/

We only care about directories within the certs/, but the code as-is
complains if there are files.

This patch makes the iteration skip non-directories entirely.

Thanks to Martin Ferrari for the bug report!

chasquid.go +8 -2

diff --git a/chasquid.go b/chasquid.go
index 2b009d4..80fb3af 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -94,13 +94,19 @@ func main() {
 	log.Infof("Loading certificates")
 	for _, info := range mustReadDir("certs/") {
 		name := info.Name()
+		dir := filepath.Join("certs/", name)
+		if fi, err := os.Stat(dir); err == nil && !fi.IsDir() {
+			// Skip non-directories.
+			continue
+		}
+
 		log.Infof("  %s", name)
 
-		certPath := filepath.Join("certs/", name, "fullchain.pem")
+		certPath := filepath.Join(dir, "fullchain.pem")
 		if _, err := os.Stat(certPath); os.IsNotExist(err) {
 			continue
 		}
-		keyPath := filepath.Join("certs/", name, "privkey.pem")
+		keyPath := filepath.Join(dir, "privkey.pem")
 		if _, err := os.Stat(keyPath); os.IsNotExist(err) {
 			continue
 		}