get(Hook)Files: Use getFile, handle globs and dirs (MR 14)
This commit includes three changes: 1. Use getFile in getHookFiles to add the contents of file hooks 2. Within getFile, first attempted a glob expansion on the specified file expression. This allows specifying e.g. /lib/udev/rules.d/*.rules. 3. Within getFile, next if the path points to a directory, add all files including those from subdirectories. This allows specifying e.g. /usr/share/X11/xkb. Relates to: postmarketOS/pmaports#1309
This commit is contained in:
committed by
Clayton Craft
parent
7a61e5126c
commit
e91a593d44
37
main.go
37
main.go
@@ -156,10 +156,9 @@ func getHookFiles(filesdir string) misc.StringSet {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
s := bufio.NewScanner(f)
|
s := bufio.NewScanner(f)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
if !exists(s.Text()) {
|
if err := getFile(files, s.Text(), true); err != nil {
|
||||||
log.Fatalf("Unable to find file %q required by %q", s.Text(), path)
|
log.Fatalf("Unable to find file %q required by %q", s.Text(), path)
|
||||||
}
|
}
|
||||||
files[s.Text()] = false
|
|
||||||
}
|
}
|
||||||
if err := s.Err(); err != nil {
|
if err := s.Err(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -243,13 +242,42 @@ func getFiles(files misc.StringSet, newFiles misc.StringSet, required bool) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getFile(files misc.StringSet, file string, required bool) error {
|
func getFile(files misc.StringSet, file string, required bool) error {
|
||||||
if !exists(file) {
|
// Expand glob expression
|
||||||
|
expanded, _ := filepath.Glob(file)
|
||||||
|
if len(expanded) > 0 && expanded[0] != file {
|
||||||
|
for _, path := range expanded {
|
||||||
|
if err := getFile(files, path, required); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fileInfo, err := os.Stat(file)
|
||||||
|
if err != nil {
|
||||||
if required {
|
if required {
|
||||||
return errors.New("getFile: File does not exist :" + file)
|
return errors.New("getFile: File does not exist :" + file)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fileInfo.IsDir() {
|
||||||
|
// Recurse over directory contents
|
||||||
|
err := filepath.Walk(file, func(path string, f os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if f.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return getFile(files, path, required)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
files[file] = false
|
files[file] = false
|
||||||
|
|
||||||
// get dependencies for binaries
|
// get dependencies for binaries
|
||||||
@@ -258,8 +286,7 @@ func getFile(files misc.StringSet, file string, required bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := getBinaryDeps(files, file)
|
if err := getBinaryDeps(files, file); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user