internal/archive: make archiveItem.add private

This commit is contained in:
Clayton Craft
2023-02-17 21:54:49 -08:00
parent fb52066d8f
commit 6fdc8937b5
3 changed files with 14 additions and 14 deletions

View File

@@ -140,9 +140,9 @@ func getInitfsExtraFiles(devinfo deviceinfo.DeviceInfo) (files []string, err err
log.Println("== Generating initramfs extra ==") log.Println("== Generating initramfs extra ==")
// Hook files & scripts // Hook files & scripts
if misc.Exists("/etc/postmarketos-mkinitfs/files-extra") { if misc.Exists("/etc/mkinitfs/files-extra") {
log.Println("- Including hook files") log.Println("- Including hook files")
hookFiles := hookfiles.New("/etc/postmarketos-mkinitfs/files-extra") hookFiles := hookfiles.New("/etc/mkinitfs/files-extra")
if list, err := hookFiles.List(); err != nil { if list, err := hookFiles.List(); err != nil {
return nil, err return nil, err
@@ -151,9 +151,9 @@ func getInitfsExtraFiles(devinfo deviceinfo.DeviceInfo) (files []string, err err
} }
} }
if misc.Exists("/etc/postmarketos-mkinitfs/hooks-extra") { if misc.Exists("/etc/mkinitfs/hooks-extra") {
log.Println("- Including extra hook scripts") log.Println("- Including extra hook scripts")
hookScripts := hookscripts.New("/etc/postmarketos-mkinitfs/hooks-extra") hookScripts := hookscripts.New("/etc/mkinitfs/hooks-extra")
if list, err := hookScripts.List(); err != nil { if list, err := hookScripts.List(); err != nil {
return nil, err return nil, err
@@ -173,11 +173,11 @@ func getInitfsExtraFiles(devinfo deviceinfo.DeviceInfo) (files []string, err err
return return
} }
func getInitfsFiles(devinfo deviceinfo.DeviceInfo) (files []string, err error) { func getInitfsFiles(devinfo deviceinfo.DeviceInfo, files misc.Items) (err error) {
log.Println("== Generating initramfs ==") log.Println("== Generating initramfs ==")
// Hook files & scripts // Hook files & scripts
if misc.Exists("/etc/postmarketos-mkinitfs/files") { if misc.Exists("/etc/mkinitfs/files") {
log.Println("- Including hook files") log.Println("- Including hook files")
hookFiles := hookfiles.New("/etc/postmarketos-mkinitfs/files") hookFiles := hookfiles.New("/etc/postmarketos-mkinitfs/files")
@@ -188,9 +188,9 @@ func getInitfsFiles(devinfo deviceinfo.DeviceInfo) (files []string, err error) {
} }
} }
if misc.Exists("/etc/postmarketos-mkinitfs/hooks") { if misc.Exists("/etc/mkinitfs/hooks") {
log.Println("- Including hook scripts") log.Println("- Including hook scripts")
hookScripts := hookscripts.New("/etc/postmarketos-mkinitfs/hooks") hookScripts := hookscripts.New("/etc/mkinitfs/hooks")
if list, err := hookScripts.List(); err != nil { if list, err := hookScripts.List(); err != nil {
return nil, err return nil, err
@@ -287,7 +287,7 @@ func generateInitfs(name string, path string, kernVer string, devinfo deviceinfo
} }
// initfs_functions // initfs_functions
if err := initfsArchive.AddItem("/usr/share/postmarketos-mkinitfs/init_functions.sh", "/init_functions.sh"); err != nil { if err := initfsArchive.AddItem("/usr/share/mkinitfs/init_functions.sh", "/init_functions.sh"); err != nil {
return err return err
} }

View File

@@ -49,7 +49,7 @@ type archiveItems struct {
// Adds the given item to the archiveItems, only if it doesn't already exist in // Adds the given item to the archiveItems, only if it doesn't already exist in
// the list. The items are kept sorted in ascending order. // the list. The items are kept sorted in ascending order.
func (a *archiveItems) Add(item archiveItem) { func (a *archiveItems) add(item archiveItem) {
a.Lock() a.Lock()
defer a.Unlock() defer a.Unlock()
@@ -170,7 +170,7 @@ func (archive *Archive) addFile(source string, dest string) error {
destFilename := strings.TrimPrefix(dest, "/") destFilename := strings.TrimPrefix(dest, "/")
archive.items.Add(archiveItem{ archive.items.add(archiveItem{
sourcePath: source, sourcePath: source,
header: &cpio.Header{ header: &cpio.Header{
Name: destFilename, Name: destFilename,
@@ -200,7 +200,7 @@ func (archive *Archive) addFile(source string, dest string) error {
destFilename := strings.TrimPrefix(dest, "/") destFilename := strings.TrimPrefix(dest, "/")
archive.items.Add(archiveItem{ archive.items.add(archiveItem{
sourcePath: source, sourcePath: source,
header: &cpio.Header{ header: &cpio.Header{
Name: destFilename, Name: destFilename,
@@ -295,7 +295,7 @@ func (archive *Archive) addDir(dir string) error {
subdirs := strings.Split(strings.TrimPrefix(dir, "/"), "/") subdirs := strings.Split(strings.TrimPrefix(dir, "/"), "/")
for i, subdir := range subdirs { for i, subdir := range subdirs {
path := filepath.Join(strings.Join(subdirs[:i], "/"), subdir) path := filepath.Join(strings.Join(subdirs[:i], "/"), subdir)
archive.items.Add(archiveItem{ archive.items.add(archiveItem{
sourcePath: path, sourcePath: path,
header: &cpio.Header{ header: &cpio.Header{
Name: path, Name: path,

View File

@@ -180,7 +180,7 @@ func TestArchiveItemsAdd(t *testing.T) {
for _, st := range subtests { for _, st := range subtests {
t.Run(st.name, func(t *testing.T) { t.Run(st.name, func(t *testing.T) {
a := archiveItems{items: st.inItems} a := archiveItems{items: st.inItems}
a.Add(st.inItem) a.add(st.inItem)
if !reflect.DeepEqual(st.expected, a.items) { if !reflect.DeepEqual(st.expected, a.items) {
t.Fatal("expected:", st.expected, " got: ", a.items) t.Fatal("expected:", st.expected, " got: ", a.items)
} }