archive: rename AddFile to addFile, and add AddItem method (MR 22)
AddItem can be used for adding either a file or directory. AddFile was made a private/internal method in this change
This commit is contained in:
6
main.go
6
main.go
@@ -649,7 +649,7 @@ func generateInitfs(name string, path string, kernVer string, devinfo deviceinfo
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := initfsArchive.AddFile("/usr/share/postmarketos-mkinitfs/init.sh", "/init"); err != nil {
|
if err := initfsArchive.AddItem("/usr/share/postmarketos-mkinitfs/init.sh", "/init"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,13 +658,13 @@ func generateInitfs(name string, path string, kernVer string, devinfo deviceinfo
|
|||||||
splashFiles, _ := filepath.Glob("/usr/share/postmarketos-splashes/*.ppm.gz")
|
splashFiles, _ := filepath.Glob("/usr/share/postmarketos-splashes/*.ppm.gz")
|
||||||
for _, file := range splashFiles {
|
for _, file := range splashFiles {
|
||||||
// splash images are expected at /<file>
|
// splash images are expected at /<file>
|
||||||
if err := initfsArchive.AddFile(file, filepath.Join("/", filepath.Base(file))); err != nil {
|
if err := initfsArchive.AddItem(file, filepath.Join("/", filepath.Base(file))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initfs_functions
|
// initfs_functions
|
||||||
if err := initfsArchive.AddFile("/usr/share/postmarketos-mkinitfs/init_functions.sh", "/init_functions.sh"); err != nil {
|
if err := initfsArchive.AddItem("/usr/share/postmarketos-mkinitfs/init_functions.sh", "/init_functions.sh"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/cavaliercoder/go-cpio"
|
"github.com/cavaliercoder/go-cpio"
|
||||||
"github.com/klauspost/pgzip"
|
"github.com/klauspost/pgzip"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/misc"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -57,7 +58,22 @@ func (archive *Archive) Write(path string, mode os.FileMode) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (archive *Archive) AddFile(file string, dest string) error {
|
// Adds the given file or directory at "source" to the archive at "dest"
|
||||||
|
func (archive *Archive) AddItem(source string, dest string) error {
|
||||||
|
|
||||||
|
sourceStat, err := os.Lstat(source)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("AddItem: failed to get stat for %q: %w", source, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceStat.Mode()&os.ModeDir != 0 {
|
||||||
|
return archive.addDir(dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
return archive.addFile(source, dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (archive *Archive) addFile(file string, dest string) error {
|
||||||
if err := archive.addDir(filepath.Dir(dest)); err != nil {
|
if err := archive.addDir(filepath.Dir(dest)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -111,7 +127,7 @@ func (archive *Archive) AddFile(file string, dest string) error {
|
|||||||
// TODO: add verbose mode, print stuff like this:
|
// TODO: add verbose mode, print stuff like this:
|
||||||
// log.Printf("symlink: %q, target: %q", file, target)
|
// log.Printf("symlink: %q, target: %q", file, target)
|
||||||
// write symlink target
|
// write symlink target
|
||||||
err = archive.AddFile(target, target)
|
err = archive.addFile(target, target)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +202,7 @@ func (archive *Archive) writeCpio() error {
|
|||||||
if imported {
|
if imported {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := archive.AddFile(file, file); err != nil {
|
if err := archive.addFile(file, file); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user