misc: remove functions now in osutils, update references in project
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
|||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist/modules"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist/modules"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist/osksdl"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist/osksdl"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ func main() {
|
|||||||
|
|
||||||
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
||||||
|
|
||||||
kernVer, err := misc.GetKernelVersion()
|
kernVer, err := osutil.GetKernelVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
retCode = 1
|
retCode = 1
|
||||||
|
@@ -19,7 +19,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/internal/filelist"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Archive struct {
|
type Archive struct {
|
||||||
@@ -191,7 +191,7 @@ func (archive *Archive) addFile(source string, dest string) error {
|
|||||||
}
|
}
|
||||||
// make sure target is an absolute path
|
// make sure target is an absolute path
|
||||||
if !filepath.IsAbs(target) {
|
if !filepath.IsAbs(target) {
|
||||||
target, err = misc.RelativeSymlinkTargetToDir(target, filepath.Dir(source))
|
target, err = osutil.RelativeSymlinkTargetToDir(target, filepath.Dir(source))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Modules struct {
|
type Modules struct {
|
||||||
@@ -31,7 +32,7 @@ func New(modulesList []string, modulesListPath string) *Modules {
|
|||||||
func (m *Modules) List() (*filelist.FileList, error) {
|
func (m *Modules) List() (*filelist.FileList, error) {
|
||||||
log.Println("- Including kernel modules")
|
log.Println("- Including kernel modules")
|
||||||
|
|
||||||
kernVer, err := misc.GetKernelVersion()
|
kernVer, err := osutil.GetKernelVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFiles(list []string, required bool) (files []string, err error) {
|
func GetFiles(list []string, required bool) (files []string, err error) {
|
||||||
@@ -150,7 +152,7 @@ func getBinaryDeps(file string) ([]string, error) {
|
|||||||
return nil, fmt.Errorf("getBinaryDeps: unable to read symlink %q: %w", file, err)
|
return nil, fmt.Errorf("getBinaryDeps: unable to read symlink %q: %w", file, err)
|
||||||
}
|
}
|
||||||
if !filepath.IsAbs(target) {
|
if !filepath.IsAbs(target) {
|
||||||
target, err = RelativeSymlinkTargetToDir(target, filepath.Dir(file))
|
target, err = osutil.RelativeSymlinkTargetToDir(target, filepath.Dir(file))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -4,53 +4,11 @@
|
|||||||
package misc
|
package misc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Converts a relative symlink target path (e.g. ../../lib/foo.so), that is
|
|
||||||
// absolute path
|
|
||||||
func RelativeSymlinkTargetToDir(symPath string, dir string) (string, error) {
|
|
||||||
var path string
|
|
||||||
|
|
||||||
oldWd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
log.Print("Unable to get current working dir")
|
|
||||||
return path, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Chdir(dir); err != nil {
|
|
||||||
log.Print("Unable to change to working dir: ", dir)
|
|
||||||
return path, err
|
|
||||||
}
|
|
||||||
|
|
||||||
path, err = filepath.Abs(symPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Print("Unable to resolve abs path to: ", symPath)
|
|
||||||
return path, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Chdir(oldWd); err != nil {
|
|
||||||
log.Print("Unable to change to old working dir")
|
|
||||||
return path, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return path, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func FreeSpace(path string) (uint64, error) {
|
|
||||||
var stat unix.Statfs_t
|
|
||||||
unix.Statfs(path, &stat)
|
|
||||||
size := stat.Bavail * uint64(stat.Bsize)
|
|
||||||
return size, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge the contents of "b" into "a", overwriting any previously existing keys
|
// Merge the contents of "b" into "a", overwriting any previously existing keys
|
||||||
// in "a"
|
// in "a"
|
||||||
func Merge(a map[string]string, b map[string]string) {
|
func Merge(a map[string]string, b map[string]string) {
|
||||||
@@ -89,32 +47,6 @@ func TimeFunc(start time.Time, name string) {
|
|||||||
log.Printf("%s completed in: %s", name, elapsed)
|
log.Printf("%s completed in: %s", name, elapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKernelReleaseFile() (string, error) {
|
|
||||||
files, _ := filepath.Glob("/usr/share/kernel/*/kernel.release")
|
|
||||||
// only one kernel flavor supported
|
|
||||||
if len(files) != 1 {
|
|
||||||
return "", fmt.Errorf("only one kernel release/flavor is supported, found: %q", files)
|
|
||||||
}
|
|
||||||
|
|
||||||
return files[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetKernelVersion() (string, error) {
|
|
||||||
var version string
|
|
||||||
|
|
||||||
releaseFile, err := getKernelReleaseFile()
|
|
||||||
if err != nil {
|
|
||||||
return version, err
|
|
||||||
}
|
|
||||||
|
|
||||||
contents, err := os.ReadFile(releaseFile)
|
|
||||||
if err != nil {
|
|
||||||
return version, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.TrimSpace(string(contents)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exists tests if the given file/dir exists or not
|
// Exists tests if the given file/dir exists or not
|
||||||
func Exists(file string) bool {
|
func Exists(file string) bool {
|
||||||
if _, err := os.Stat(file); err == nil {
|
if _, err := os.Stat(file); err == nil {
|
||||||
|
Reference in New Issue
Block a user