git » kxd » commit 14eab77

kxd: Simplify Stat calls

author Alberto Bertogli
2019-08-10 09:46:30 UTC
committer Alberto Bertogli
2019-08-31 16:26:53 UTC
parent bc74d7e487ad400439fa7ec29502eeb2f8a0d083

kxd: Simplify Stat calls

Currently we open a file to do Stat, which is unnecessary and leaks file
descriptors.

This patch fixes that by using the proper os.Stat call instead.

kxd/key_config.go +2 -11

diff --git a/kxd/key_config.go b/kxd/key_config.go
index 48926fd..09f56ff 100644
--- a/kxd/key_config.go
+++ b/kxd/key_config.go
@@ -9,17 +9,8 @@ import (
 	"strings"
 )
 
-func fileStat(path string) (os.FileInfo, error) {
-	fd, err := os.Open(path)
-	if err != nil {
-		return nil, err
-	}
-
-	return fd.Stat()
-}
-
 func isDir(path string) (bool, error) {
-	fi, err := fileStat(path)
+	fi, err := os.Stat(path)
 	if err != nil {
 		return false, err
 	}
@@ -28,7 +19,7 @@ func isDir(path string) (bool, error) {
 }
 
 func isRegular(path string) (bool, error) {
-	fi, err := fileStat(path)
+	fi, err := os.Stat(path)
 	if err != nil {
 		return false, err
 	}