Compare commits
2 Commits
main
...
recurse-ho
Author | SHA1 | Date | |
---|---|---|---|
|
b54044a605 | ||
|
f0544999db |
@@ -1,6 +1,12 @@
|
||||
package filelist
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||
)
|
||||
|
||||
type FileLister interface {
|
||||
List() (*FileList, error)
|
||||
@@ -45,6 +51,26 @@ func (f *FileList) Import(src *FileList) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FileList) AddGlobbed(src string, dest string) error {
|
||||
fFiles, err := misc.GetFiles([]string{src}, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add %q: %w", src, err)
|
||||
}
|
||||
// loop over all returned files from GetFile
|
||||
for _, file := range fFiles {
|
||||
if len(fFiles) > 1 {
|
||||
// Glob with arbitrary subdirectories, so we need to
|
||||
// remove the src path and prepend the dest path
|
||||
f.Add(file, filepath.Join(dest, file[len(src):]))
|
||||
} else {
|
||||
// dest path specified, and only 1 file
|
||||
f.Add(file, dest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// iterate through the list and and send each one as a new File over the
|
||||
// returned channel
|
||||
func (f *FileList) IterItems() <-chan File {
|
||||
|
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||
)
|
||||
|
||||
type HookFiles struct {
|
||||
@@ -60,22 +59,13 @@ func slurpFiles(fd io.Reader) (*filelist.FileList, error) {
|
||||
for s.Scan() {
|
||||
src, dest, has_dest := strings.Cut(s.Text(), ":")
|
||||
|
||||
fFiles, err := misc.GetFiles([]string{src}, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to add %q: %w", src, err)
|
||||
if !has_dest {
|
||||
dest = src
|
||||
}
|
||||
// loop over all returned files from GetFile
|
||||
for _, file := range fFiles {
|
||||
if !has_dest {
|
||||
files.Add(file, file)
|
||||
} else if len(fFiles) > 1 {
|
||||
// Don't support specifying dest if src was a glob
|
||||
// NOTE: this could support this later...
|
||||
files.Add(file, file)
|
||||
} else {
|
||||
// dest path specified, and only 1 file
|
||||
files.Add(file, dest)
|
||||
}
|
||||
|
||||
err := files.AddGlobbed(src, dest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,8 +35,13 @@ func (h *HookScripts) List() (*filelist.FileList, error) {
|
||||
}
|
||||
for _, file := range fileInfo {
|
||||
path := filepath.Join(h.scriptsDir, file.Name())
|
||||
log.Printf("-- Including script: %s\n", path)
|
||||
files.Add(path, filepath.Join(h.destPath, file.Name()))
|
||||
if file.IsDir() {
|
||||
log.Printf("-- Including dir %s\n", path)
|
||||
files.AddGlobbed(filepath.Join(path, "*"), filepath.Join(h.destPath, file.Name()))
|
||||
} else {
|
||||
log.Printf("-- Including script: %s\n", path)
|
||||
files.Add(path, filepath.Join(h.destPath, file.Name()))
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user