@@ -2,7 +2,7 @@ package repo
2
2
3
3
import (
4
4
"fmt"
5
- "io/ioutil "
5
+ "io/fs "
6
6
"os"
7
7
"os/exec"
8
8
"path"
@@ -29,23 +29,32 @@ func NewRepo() (*Repo, error) {
29
29
func (repo * Repo ) FindHookExecutables (hook string ) ([]string , error ) {
30
30
dir := path .Join (".quickhook" , hook )
31
31
32
- files , err := ioutil .ReadDir (path .Join (repo .Root , dir ))
33
- if err != nil {
34
- if os .IsNotExist (err ) {
35
- return []string {}, nil
36
- } else {
32
+ var infos []fs.FileInfo
33
+ {
34
+ f , err := os .Open (path .Join (repo .Root , dir ))
35
+ if err != nil {
36
+ if os .IsNotExist (err ) {
37
+ return []string {}, nil
38
+ }
39
+ return nil , err
40
+ }
41
+ defer f .Close ()
42
+
43
+ // Using Readdir since it returns FileInfo's that include permissions, whereas ReadDir
44
+ // returns returns DirEntry's which does not.
45
+ infos , err = f .Readdir (- 1 )
46
+ if err != nil {
37
47
return nil , err
38
48
}
39
49
}
40
50
41
51
hooks := []string {}
42
- for _ , fileInfo := range files {
43
- if fileInfo .IsDir () {
52
+ for _ , info := range infos {
53
+ if info .IsDir () {
44
54
continue
45
55
}
46
-
47
- name := fileInfo .Name ()
48
- if (fileInfo .Mode () & 0111 ) > 0 {
56
+ name := info .Name ()
57
+ if (info .Mode () & 0111 ) != 0 {
49
58
hooks = append (hooks , path .Join (dir , name ))
50
59
} else {
51
60
fmt .Fprintf (os .Stderr , "Warning: Non-executable file found in %v: %v\n " , dir , name )
@@ -85,14 +94,3 @@ func (repo *Repo) isFile(name string) (bool, error) {
85
94
}
86
95
return ! stat .IsDir (), nil
87
96
}
88
-
89
- func (repo * Repo ) IsDir (name string ) (bool , error ) {
90
- stat , err := os .Stat (path .Join (repo .Root , name ))
91
- if err != nil {
92
- if os .IsNotExist (err ) {
93
- return false , nil
94
- }
95
- return false , err
96
- }
97
- return stat .IsDir (), nil
98
- }
0 commit comments