filelist/*: implement FileLister in existing types
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,13 +23,13 @@ func New(filePath string) *HookFiles {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HookFiles) List() ([]string, error) {
|
func (h *HookFiles) List() (*filelist.FileList, error) {
|
||||||
log.Println("- Including files")
|
log.Println("- Including files")
|
||||||
fileInfo, err := os.ReadDir(h.filePath)
|
fileInfo, err := os.ReadDir(h.filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("getHookFiles: unable to read hook file dir: %w", err)
|
return nil, fmt.Errorf("getHookFiles: unable to read hook file dir: %w", err)
|
||||||
}
|
}
|
||||||
files := []string{}
|
files := filelist.NewFileList()
|
||||||
for _, file := range fileInfo {
|
for _, file := range fileInfo {
|
||||||
path := filepath.Join(h.filePath, file.Name())
|
path := filepath.Join(h.filePath, file.Name())
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
@@ -40,10 +41,12 @@ func (h *HookFiles) List() ([]string, error) {
|
|||||||
log.Printf("-- Including files from: %s\n", path)
|
log.Printf("-- Including files from: %s\n", path)
|
||||||
s := bufio.NewScanner(f)
|
s := bufio.NewScanner(f)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
if filelist, err := misc.GetFiles([]string{s.Text()}, true); err != nil {
|
if fFiles, err := misc.GetFiles([]string{s.Text()}, true); err != nil {
|
||||||
return nil, fmt.Errorf("getHookFiles: unable to add file %q required by %q: %w", s.Text(), path, err)
|
return nil, fmt.Errorf("getHookFiles: unable to add file %q required by %q: %w", s.Text(), path, err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range fFiles {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := s.Err(); err != nil {
|
if err := s.Err(); err != nil {
|
||||||
|
@@ -5,6 +5,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HookScripts struct {
|
type HookScripts struct {
|
||||||
@@ -19,8 +21,8 @@ func New(scriptsDir string) *HookScripts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HookScripts) List() ([]string, error) {
|
func (h *HookScripts) List() (*filelist.FileList, error) {
|
||||||
files := []string{}
|
files := filelist.NewFileList()
|
||||||
log.Println("- Including hook scripts")
|
log.Println("- Including hook scripts")
|
||||||
|
|
||||||
fileInfo, err := os.ReadDir(h.scriptsDir)
|
fileInfo, err := os.ReadDir(h.scriptsDir)
|
||||||
@@ -29,7 +31,7 @@ func (h *HookScripts) List() ([]string, error) {
|
|||||||
}
|
}
|
||||||
for _, file := range fileInfo {
|
for _, file := range fileInfo {
|
||||||
path := filepath.Join(h.scriptsDir, file.Name())
|
path := filepath.Join(h.scriptsDir, file.Name())
|
||||||
files = append(files, path)
|
files.Add(path, path)
|
||||||
}
|
}
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ func New(modules []string) *Modules {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Modules) List() ([]string, error) {
|
func (m *Modules) List() (*filelist.FileList, error) {
|
||||||
log.Println("- Including kernel modules")
|
log.Println("- Including kernel modules")
|
||||||
|
|
||||||
kernVer, err := misc.GetKernelVersion()
|
kernVer, err := misc.GetKernelVersion()
|
||||||
@@ -33,7 +34,7 @@ func (m *Modules) List() ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files := []string{}
|
files := filelist.NewFileList()
|
||||||
|
|
||||||
modDir := filepath.Join("/lib/modules", kernVer)
|
modDir := filepath.Join("/lib/modules", kernVer)
|
||||||
if !misc.Exists(modDir) {
|
if !misc.Exists(modDir) {
|
||||||
@@ -44,14 +45,18 @@ func (m *Modules) List() ([]string, error) {
|
|||||||
|
|
||||||
// modules.* required by modprobe
|
// modules.* required by modprobe
|
||||||
modprobeFiles, _ := filepath.Glob(filepath.Join(modDir, "modules.*"))
|
modprobeFiles, _ := filepath.Glob(filepath.Join(modDir, "modules.*"))
|
||||||
files = append(files, modprobeFiles...)
|
for _, file := range modprobeFiles {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
|
|
||||||
// deviceinfo modules
|
// deviceinfo modules
|
||||||
for _, module := range m.modules {
|
for _, module := range m.modules {
|
||||||
if filelist, err := getModule(module, modDir); err != nil {
|
if modFilelist, err := getModule(module, modDir); err != nil {
|
||||||
return nil, fmt.Errorf("getInitfsModules: unable to get modules from deviceinfo: %w", err)
|
return nil, fmt.Errorf("getInitfsModules: unable to get modules from deviceinfo: %w", err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range modFilelist {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,10 +70,12 @@ func (m *Modules) List() ([]string, error) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
s := bufio.NewScanner(f)
|
s := bufio.NewScanner(f)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
if filelist, err := getModule(s.Text(), modDir); err != nil {
|
if modFilelist, err := getModule(s.Text(), modDir); err != nil {
|
||||||
return nil, fmt.Errorf("getInitfsModules: unable to get module file %q: %w", s.Text(), err)
|
return nil, fmt.Errorf("getInitfsModules: unable to get module file %q: %w", s.Text(), err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range modFilelist {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,12 +26,14 @@ func New(mesaDriverName string) *OskSdl {
|
|||||||
|
|
||||||
// Get a list of files and their dependencies related to supporting rootfs full
|
// Get a list of files and their dependencies related to supporting rootfs full
|
||||||
// disk (d)encryption
|
// disk (d)encryption
|
||||||
func (s *OskSdl) List() ([]string, error) {
|
func (s *OskSdl) List() (*filelist.FileList, error) {
|
||||||
if !misc.Exists("/usr/bin/osk-sdl") {
|
if !misc.Exists("/usr/bin/osk-sdl") {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
log.Println("- Including osk-sdl support")
|
log.Println("- Including osk-sdl support")
|
||||||
|
|
||||||
|
files := filelist.NewFileList()
|
||||||
|
|
||||||
confFiles := []string{
|
confFiles := []string{
|
||||||
"/etc/osk.conf",
|
"/etc/osk.conf",
|
||||||
"/etc/ts.conf",
|
"/etc/ts.conf",
|
||||||
@@ -38,10 +41,13 @@ func (s *OskSdl) List() ([]string, error) {
|
|||||||
"/etc/fb.modes",
|
"/etc/fb.modes",
|
||||||
"/etc/directfbrc",
|
"/etc/directfbrc",
|
||||||
}
|
}
|
||||||
files, err := misc.GetFiles(confFiles, false)
|
confFileList, err := misc.GetFiles(confFiles, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
||||||
}
|
}
|
||||||
|
for _, file := range confFileList {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
|
|
||||||
// osk-sdl
|
// osk-sdl
|
||||||
oskFiles := []string{
|
oskFiles := []string{
|
||||||
@@ -49,17 +55,19 @@ func (s *OskSdl) List() ([]string, error) {
|
|||||||
"/sbin/cryptsetup",
|
"/sbin/cryptsetup",
|
||||||
"/usr/lib/libGL.so.1",
|
"/usr/lib/libGL.so.1",
|
||||||
}
|
}
|
||||||
if filelist, err := misc.GetFiles(oskFiles, true); err != nil {
|
if oskFileList, err := misc.GetFiles(oskFiles, true); err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range oskFileList {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fontFile, err := getOskConfFontPath("/etc/osk.conf")
|
fontFile, err := getOskConfFontPath("/etc/osk.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add file %q: %w", fontFile, err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add file %q: %w", fontFile, err)
|
||||||
}
|
}
|
||||||
files = append(files, fontFile)
|
files.Add(fontFile, fontFile)
|
||||||
|
|
||||||
// Directfb
|
// Directfb
|
||||||
dfbFiles := []string{}
|
dfbFiles := []string{}
|
||||||
@@ -72,10 +80,12 @@ func (s *OskSdl) List() ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add file %w", err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add file %w", err)
|
||||||
}
|
}
|
||||||
if filelist, err := misc.GetFiles(dfbFiles, true); err != nil {
|
if dfbFileList, err := misc.GetFiles(dfbFiles, true); err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range dfbFileList {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslib
|
// tslib
|
||||||
@@ -91,10 +101,12 @@ func (s *OskSdl) List() ([]string, error) {
|
|||||||
}
|
}
|
||||||
libts, _ := filepath.Glob("/usr/lib/libts*")
|
libts, _ := filepath.Glob("/usr/lib/libts*")
|
||||||
tslibFiles = append(tslibFiles, libts...)
|
tslibFiles = append(tslibFiles, libts...)
|
||||||
if filelist, err := misc.GetFiles(tslibFiles, true); err != nil {
|
if tslibFileList, err := misc.GetFiles(tslibFiles, true); err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range tslibFileList {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mesa hw accel
|
// mesa hw accel
|
||||||
@@ -106,10 +118,12 @@ func (s *OskSdl) List() ([]string, error) {
|
|||||||
"/usr/lib/libudev.so.1",
|
"/usr/lib/libudev.so.1",
|
||||||
"/usr/lib/xorg/modules/dri/" + s.mesaDriver + "_dri.so",
|
"/usr/lib/xorg/modules/dri/" + s.mesaDriver + "_dri.so",
|
||||||
}
|
}
|
||||||
if filelist, err := misc.GetFiles(mesaFiles, true); err != nil {
|
if mesaFileList, err := misc.GetFiles(mesaFiles, true); err != nil {
|
||||||
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
return nil, fmt.Errorf("getFdeFiles: failed to add files: %w", err)
|
||||||
} else {
|
} else {
|
||||||
files = append(files, filelist...)
|
for _, file := range mesaFileList {
|
||||||
|
files.Add(file, file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user