Compare commits
1 Commits
2.6.3
...
caleb/mult
Author | SHA1 | Date | |
---|---|---|---|
|
2e37a7c645 |
120
.gitlab-ci.yml
120
.gitlab-ci.yml
@@ -6,123 +6,43 @@ image: alpine:edge
|
|||||||
variables:
|
variables:
|
||||||
GOFLAGS: "-buildvcs=false"
|
GOFLAGS: "-buildvcs=false"
|
||||||
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/mkinitfs-vendor-${CI_COMMIT_TAG}/${CI_COMMIT_TAG}"
|
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/mkinitfs-vendor-${CI_COMMIT_TAG}/${CI_COMMIT_TAG}"
|
||||||
CI_TRON_TEMPLATE_PROJECT: &ci-tron-template-project postmarketOS/ci-common
|
|
||||||
CI_TRON_JOB_TEMPLATE_PROJECT_URL: $CI_SERVER_URL/$CI_TRON_TEMPLATE_PROJECT
|
|
||||||
CI_TRON_JOB_TEMPLATE_COMMIT: &ci-tron-template-commit 7c95b5f2d53533e8722abf57c73e558168e811f3
|
|
||||||
|
|
||||||
include:
|
|
||||||
- project: *ci-tron-template-project
|
|
||||||
ref: *ci-tron-template-commit
|
|
||||||
file: '/ci-tron/common.yml'
|
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- lint
|
||||||
- build
|
- build
|
||||||
- hardware tests
|
|
||||||
- vendor
|
- vendor
|
||||||
- release
|
- release
|
||||||
|
|
||||||
workflow:
|
# defaults for "only"
|
||||||
rules:
|
# We need to run the CI jobs in a "merge request specific context", if CI is
|
||||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
# running in a merge request. Otherwise the environment variable that holds the
|
||||||
- if: $CI_COMMIT_BRANCH == 'master'
|
# merge request ID is not available. This means, we must set the "only"
|
||||||
- if: '$CI_COMMIT_TAG != null'
|
# variable accordingly - and if we only do it for one job, all other jobs will
|
||||||
|
# not get executed. So have the defaults here, and use them in all jobs that
|
||||||
|
# should run on both the master branch, and in merge requests.
|
||||||
|
# https://docs.gitlab.com/ee/ci/merge_request_pipelines/index.html#excluding-certain-jobs
|
||||||
|
.only-default: &only-default
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- merge_requests
|
||||||
|
- tags
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
variables:
|
<<: *only-default
|
||||||
GOTEST: "gotestsum --junitfile report.xml --format testname -- ./..."
|
|
||||||
parallel:
|
|
||||||
matrix:
|
|
||||||
- TAG: shared
|
|
||||||
- TAG: arm64
|
|
||||||
tags:
|
|
||||||
- $TAG
|
|
||||||
before_script:
|
before_script:
|
||||||
- apk -q add go gotestsum staticcheck make scdoc
|
- apk -q add go staticcheck make scdoc
|
||||||
script:
|
script:
|
||||||
- make test
|
- make test
|
||||||
- make
|
- make
|
||||||
after_script:
|
|
||||||
- mkdir -p rootfs/usr/sbin
|
|
||||||
- cp mkinitfs rootfs/usr/sbin
|
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
reports:
|
|
||||||
junit: report.xml
|
|
||||||
paths:
|
|
||||||
- rootfs
|
|
||||||
|
|
||||||
.qemu-common:
|
|
||||||
variables:
|
|
||||||
DEVICE_NAME: qemu-$CPU_ARCH
|
|
||||||
KERNEL_VARIANT: lts
|
|
||||||
|
|
||||||
.build-ci-tron-qemu:
|
|
||||||
stage: hardware tests
|
|
||||||
extends:
|
|
||||||
- .pmos-ci-tron-build-boot-artifacts
|
|
||||||
- .qemu-common
|
|
||||||
variables:
|
|
||||||
INSTALL_PACKAGES: device-${DEVICE_NAME} device-${DEVICE_NAME}-kernel-${KERNEL_VARIANT} postmarketos-mkinitfs-hook-ci
|
|
||||||
|
|
||||||
build-ci-tron-qemu-amd64:
|
|
||||||
extends:
|
|
||||||
- .build-ci-tron-qemu
|
|
||||||
needs:
|
|
||||||
- job: "build"
|
|
||||||
parallel:
|
|
||||||
matrix:
|
|
||||||
- TAG: shared
|
|
||||||
variables:
|
|
||||||
CPU_ARCH: amd64
|
|
||||||
|
|
||||||
build-ci-tron-qemu-aarch64:
|
|
||||||
extends:
|
|
||||||
- .build-ci-tron-qemu
|
|
||||||
needs:
|
|
||||||
- job: "build"
|
|
||||||
parallel:
|
|
||||||
matrix:
|
|
||||||
- TAG: arm64
|
|
||||||
variables:
|
|
||||||
CPU_ARCH: aarch64
|
|
||||||
|
|
||||||
.test-ci-tron-qemu:
|
|
||||||
stage: hardware tests
|
|
||||||
extends:
|
|
||||||
- .pmos-ci-tron-initramfs-test
|
|
||||||
- .qemu-common
|
|
||||||
dependencies: []
|
|
||||||
variables:
|
|
||||||
CI_TRON_KERNEL__URL: "glartifact://build-ci-tron-qemu-$CPU_ARCH/${CI_TRON__PMB_EXPORT_PATH}/vmlinuz-${KERNEL_VARIANT}"
|
|
||||||
CI_TRON_INITRAMFS__INITRAMFS__URL: "glartifact://build-ci-tron-qemu-$CPU_ARCH/${CI_TRON__PMB_EXPORT_PATH}/initramfs"
|
|
||||||
CI_TRON_KERNEL_CMDLINE__DEVICEINFO: 'console=tty1 console=ttyS0,115200 PMOS_FORCE_PARTITION_RESIZE'
|
|
||||||
|
|
||||||
test-ci-tron-qemu-amd64:
|
|
||||||
extends:
|
|
||||||
- .test-ci-tron-qemu
|
|
||||||
- .pmos-ci-tron-runner-qemu-amd64
|
|
||||||
needs:
|
|
||||||
- job: 'build-ci-tron-qemu-amd64'
|
|
||||||
artifacts: false
|
|
||||||
variables:
|
|
||||||
CPU_ARCH: amd64
|
|
||||||
|
|
||||||
test-ci-tron-qemu-aarch64:
|
|
||||||
extends:
|
|
||||||
- .test-ci-tron-qemu
|
|
||||||
- .pmos-ci-tron-runner-qemu-aarch64
|
|
||||||
needs:
|
|
||||||
- job: 'build-ci-tron-qemu-aarch64'
|
|
||||||
artifacts: false
|
|
||||||
variables:
|
|
||||||
CPU_ARCH: aarch64
|
|
||||||
|
|
||||||
vendor:
|
vendor:
|
||||||
stage: vendor
|
stage: vendor
|
||||||
image: alpine:latest
|
image: alpine:latest
|
||||||
rules:
|
only:
|
||||||
- if: '$CI_COMMIT_TAG != null'
|
- tags
|
||||||
before_script:
|
before_script:
|
||||||
- apk -q add curl go make
|
- apk -q add curl go make
|
||||||
script:
|
script:
|
||||||
@@ -134,8 +54,8 @@ vendor:
|
|||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||||
rules:
|
only:
|
||||||
- if: '$CI_COMMIT_TAG != null'
|
- tags
|
||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
|
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
|
||||||
|
5
Makefile
5
Makefile
@@ -12,8 +12,7 @@ GO?=go
|
|||||||
GOFLAGS?=
|
GOFLAGS?=
|
||||||
LDFLAGS+=-s -w -X main.Version=$(VERSION)
|
LDFLAGS+=-s -w -X main.Version=$(VERSION)
|
||||||
RM?=rm -f
|
RM?=rm -f
|
||||||
GOTESTOPTS?=-count=1 -race
|
GOTEST=go test -count=1 -race
|
||||||
GOTEST?=go test ./...
|
|
||||||
DISABLE_GOGC?=
|
DISABLE_GOGC?=
|
||||||
|
|
||||||
ifeq ($(DISABLE_GOGC),1)
|
ifeq ($(DISABLE_GOGC),1)
|
||||||
@@ -48,7 +47,7 @@ test:
|
|||||||
fi
|
fi
|
||||||
@staticcheck ./...
|
@staticcheck ./...
|
||||||
|
|
||||||
$(GOTEST) $(GOTESTOPTS)
|
@$(GOTEST) ./...
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) mkinitfs $(DOCS)
|
$(RM) mkinitfs $(DOCS)
|
||||||
|
@@ -40,6 +40,7 @@ func main() {
|
|||||||
defer func() { os.Exit(retCode) }()
|
defer func() { os.Exit(retCode) }()
|
||||||
|
|
||||||
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
||||||
|
kernVerArg := flag.String("k", "guess", "Kernel version to run for")
|
||||||
|
|
||||||
var showVersion bool
|
var showVersion bool
|
||||||
flag.BoolVar(&showVersion, "version", false, "Print version and quit.")
|
flag.BoolVar(&showVersion, "version", false, "Print version and quit.")
|
||||||
@@ -48,6 +49,8 @@ func main() {
|
|||||||
flag.BoolVar(&disableBootDeploy, "no-bootdeploy", false, "Disable running 'boot-deploy' after generating archives.")
|
flag.BoolVar(&disableBootDeploy, "no-bootdeploy", false, "Disable running 'boot-deploy' after generating archives.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
kernVer := *kernVerArg
|
||||||
|
|
||||||
if showVersion {
|
if showVersion {
|
||||||
fmt.Printf("%s - %s\n", filepath.Base(os.Args[0]), Version)
|
fmt.Printf("%s - %s\n", filepath.Base(os.Args[0]), Version)
|
||||||
return
|
return
|
||||||
@@ -68,11 +71,14 @@ func main() {
|
|||||||
|
|
||||||
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
||||||
|
|
||||||
kernVer, err := osutil.GetKernelVersion()
|
if kernVer == "guess" {
|
||||||
if err != nil {
|
_kernVer, err := osutil.GetKernelVersion()
|
||||||
log.Println(err)
|
if err != nil {
|
||||||
retCode = 1
|
log.Println(err)
|
||||||
return
|
retCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
kernVer = _kernVer
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporary working dir
|
// temporary working dir
|
||||||
@@ -111,16 +117,16 @@ func main() {
|
|||||||
hookfiles.New("/etc/mkinitfs/files"),
|
hookfiles.New("/etc/mkinitfs/files"),
|
||||||
hookscripts.New("/usr/share/mkinitfs/hooks", "/hooks"),
|
hookscripts.New("/usr/share/mkinitfs/hooks", "/hooks"),
|
||||||
hookscripts.New("/etc/mkinitfs/hooks", "/hooks"),
|
hookscripts.New("/etc/mkinitfs/hooks", "/hooks"),
|
||||||
modules.New("/usr/share/mkinitfs/modules"),
|
modules.New("/usr/share/mkinitfs/modules", kernVer),
|
||||||
modules.New("/etc/mkinitfs/modules"),
|
modules.New("/etc/mkinitfs/modules", kernVer),
|
||||||
})
|
})
|
||||||
initfsExtra := initramfs.New([]filelist.FileLister{
|
initfsExtra := initramfs.New([]filelist.FileLister{
|
||||||
hookfiles.New("/usr/share/mkinitfs/files-extra"),
|
hookfiles.New("/usr/share/mkinitfs/files-extra"),
|
||||||
hookfiles.New("/etc/mkinitfs/files-extra"),
|
hookfiles.New("/etc/mkinitfs/files-extra"),
|
||||||
hookscripts.New("/usr/share/mkinitfs/hooks-extra", "/hooks-extra"),
|
hookscripts.New("/usr/share/mkinitfs/hooks-extra", "/hooks-extra"),
|
||||||
hookscripts.New("/etc/mkinitfs/hooks-extra", "/hooks-extra"),
|
hookscripts.New("/etc/mkinitfs/hooks-extra", "/hooks-extra"),
|
||||||
modules.New("/usr/share/mkinitfs/modules-extra"),
|
modules.New("/usr/share/mkinitfs/modules-extra", kernVer),
|
||||||
modules.New("/etc/mkinitfs/modules-extra"),
|
modules.New("/etc/mkinitfs/modules-extra", kernVer),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := initramfsAr.AddItems(initfs); err != nil {
|
if err := initramfsAr.AddItems(initfs); err != nil {
|
||||||
@@ -141,7 +147,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := initramfsAr.Write(filepath.Join(workDir, "initramfs"), os.FileMode(0644)); err != nil {
|
if err := initramfsAr.Write(filepath.Join(workDir, fmt.Sprintf("initramfs-%s", kernVer)), os.FileMode(0644)); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("failed to generate: ", "initramfs")
|
log.Println("failed to generate: ", "initramfs")
|
||||||
retCode = 1
|
retCode = 1
|
||||||
@@ -177,7 +183,7 @@ func main() {
|
|||||||
|
|
||||||
// Final processing of initramfs / kernel is done by boot-deploy
|
// Final processing of initramfs / kernel is done by boot-deploy
|
||||||
if !disableBootDeploy {
|
if !disableBootDeploy {
|
||||||
if err := bootDeploy(workDir, *outDir, devinfo); err != nil {
|
if err := bootDeploy(workDir, *outDir, devinfo, kernVer); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("boot-deploy failed")
|
log.Println("boot-deploy failed")
|
||||||
retCode = 1
|
retCode = 1
|
||||||
@@ -186,10 +192,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func bootDeploy(workDir string, outDir string, devinfo deviceinfo.DeviceInfo) error {
|
func bootDeploy(workDir string, outDir string, devinfo deviceinfo.DeviceInfo, kernVer string) error {
|
||||||
log.Print("== Using boot-deploy to finalize/install files ==")
|
log.Print("== Using boot-deploy to finalize/install files ==")
|
||||||
defer misc.TimeFunc(time.Now(), "boot-deploy")
|
defer misc.TimeFunc(time.Now(), "boot-deploy")
|
||||||
|
|
||||||
bd := bootdeploy.New(workDir, outDir, devinfo)
|
bd := bootdeploy.New(workDir, outDir, devinfo, kernVer)
|
||||||
return bd.Run()
|
return bd.Run()
|
||||||
}
|
}
|
||||||
|
@@ -421,6 +421,7 @@ func (archive *Archive) writeCpio() error {
|
|||||||
archive.addSymlink("/bin", "/bin")
|
archive.addSymlink("/bin", "/bin")
|
||||||
archive.addSymlink("/sbin", "/sbin")
|
archive.addSymlink("/sbin", "/sbin")
|
||||||
archive.addSymlink("/lib", "/lib")
|
archive.addSymlink("/lib", "/lib")
|
||||||
|
archive.addSymlink("/usr/sbin", "/usr/sbin")
|
||||||
}
|
}
|
||||||
// having a transient function for actually adding files to the archive
|
// having a transient function for actually adding files to the archive
|
||||||
// allows the deferred fd.close to run after every copy and prevent having
|
// allows the deferred fd.close to run after every copy and prevent having
|
||||||
|
@@ -18,6 +18,7 @@ type BootDeploy struct {
|
|||||||
inDir string
|
inDir string
|
||||||
outDir string
|
outDir string
|
||||||
devinfo deviceinfo.DeviceInfo
|
devinfo deviceinfo.DeviceInfo
|
||||||
|
kernVer string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new BootDeploy, which then runs:
|
// New returns a new BootDeploy, which then runs:
|
||||||
@@ -26,11 +27,12 @@ type BootDeploy struct {
|
|||||||
//
|
//
|
||||||
// devinfo is used to access some deviceinfo values, such as UbootBoardname
|
// devinfo is used to access some deviceinfo values, such as UbootBoardname
|
||||||
// and GenerateSystemdBoot
|
// and GenerateSystemdBoot
|
||||||
func New(inDir string, outDir string, devinfo deviceinfo.DeviceInfo) *BootDeploy {
|
func New(inDir string, outDir string, devinfo deviceinfo.DeviceInfo, kernVer string) *BootDeploy {
|
||||||
return &BootDeploy{
|
return &BootDeploy{
|
||||||
inDir: inDir,
|
inDir: inDir,
|
||||||
outDir: outDir,
|
outDir: outDir,
|
||||||
devinfo: devinfo,
|
devinfo: devinfo,
|
||||||
|
kernVer: kernVer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,10 +45,11 @@ func (b *BootDeploy) Run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kernels, err := getKernelPath(b.outDir, b.devinfo.GenerateSystemdBoot == "true")
|
kernels, err := getKernelPath(b.outDir, b.kernVer, b.devinfo.GenerateSystemdBoot == "true")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
println(fmt.Sprintf("kernels: %v\n", kernels))
|
||||||
|
|
||||||
// Pick a kernel that does not have suffixes added by boot-deploy
|
// Pick a kernel that does not have suffixes added by boot-deploy
|
||||||
var kernFile string
|
var kernFile string
|
||||||
@@ -79,8 +82,9 @@ func (b *BootDeploy) Run() error {
|
|||||||
|
|
||||||
// boot-deploy -i initramfs -k vmlinuz-postmarketos-rockchip -d /tmp/cpio -o /tmp/foo initramfs-extra
|
// boot-deploy -i initramfs -k vmlinuz-postmarketos-rockchip -d /tmp/cpio -o /tmp/foo initramfs-extra
|
||||||
args := []string{
|
args := []string{
|
||||||
"-i", "initramfs",
|
"-i", fmt.Sprintf("initramfs-%s", b.kernVer),
|
||||||
"-k", kernFilename,
|
"-k", kernFilename,
|
||||||
|
"-v", b.kernVer,
|
||||||
"-d", b.inDir,
|
"-d", b.inDir,
|
||||||
"-o", b.outDir,
|
"-o", b.outDir,
|
||||||
}
|
}
|
||||||
@@ -88,6 +92,7 @@ func (b *BootDeploy) Run() error {
|
|||||||
if b.devinfo.CreateInitfsExtra {
|
if b.devinfo.CreateInitfsExtra {
|
||||||
args = append(args, "initramfs-extra")
|
args = append(args, "initramfs-extra")
|
||||||
}
|
}
|
||||||
|
println(fmt.Sprintf("Calling boot-deply with args: %v\n", args))
|
||||||
cmd := exec.Command("boot-deploy", args...)
|
cmd := exec.Command("boot-deploy", args...)
|
||||||
|
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -99,20 +104,20 @@ func (b *BootDeploy) Run() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKernelPath(outDir string, zboot bool) ([]string, error) {
|
func getKernelPath(outDir string, kernVer string, zboot bool) ([]string, error) {
|
||||||
var kernels []string
|
var kernels []string
|
||||||
if zboot {
|
if zboot {
|
||||||
kernels, _ = filepath.Glob(filepath.Join(outDir, "linux.efi"))
|
kernels, _ = filepath.Glob(filepath.Join(outDir, fmt.Sprintf("linux-%s.efi", kernVer)))
|
||||||
if len(kernels) > 0 {
|
if len(kernels) > 0 {
|
||||||
return kernels, nil
|
return kernels, nil
|
||||||
}
|
}
|
||||||
// else fallback to vmlinuz* below
|
// else fallback to vmlinuz* below
|
||||||
}
|
}
|
||||||
|
|
||||||
kernFile := "vmlinuz*"
|
kernFile := fmt.Sprintf("vmlinuz-%s", kernVer)
|
||||||
kernels, _ = filepath.Glob(filepath.Join(outDir, kernFile))
|
kernels, _ = filepath.Glob(filepath.Join(outDir, kernFile))
|
||||||
if len(kernels) == 0 {
|
if len(kernels) == 0 {
|
||||||
return nil, errors.New("Unable to find any kernels at " + filepath.Join(outDir, kernFile))
|
return nil, errors.New("Unable to find any kernels at " + filepath.Join(outDir, kernFile) + " or " + filepath.Join(outDir, fmt.Sprintf("linux-%s.efi", kernVer)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return kernels, nil
|
return kernels, nil
|
||||||
|
@@ -12,26 +12,22 @@ 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 {
|
||||||
modulesListPath string
|
modulesListPath string
|
||||||
|
kernVer string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Modules that will read in lists of kernel modules in the given path.
|
// New returns a new Modules that will read in lists of kernel modules in the given path.
|
||||||
func New(modulesListPath string) *Modules {
|
func New(modulesListPath string, kernVer string) *Modules {
|
||||||
return &Modules{
|
return &Modules{
|
||||||
modulesListPath: modulesListPath,
|
modulesListPath: modulesListPath,
|
||||||
|
kernVer: kernVer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Modules) List() (*filelist.FileList, error) {
|
func (m *Modules) List() (*filelist.FileList, error) {
|
||||||
kernVer, err := osutil.GetKernelVersion()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
files := filelist.NewFileList()
|
files := filelist.NewFileList()
|
||||||
libDir := "/usr/lib/modules"
|
libDir := "/usr/lib/modules"
|
||||||
if exists, err := misc.Exists(libDir); !exists {
|
if exists, err := misc.Exists(libDir); !exists {
|
||||||
@@ -40,7 +36,7 @@ func (m *Modules) List() (*filelist.FileList, error) {
|
|||||||
return nil, fmt.Errorf("received unexpected error when getting status for %q: %w", libDir, err)
|
return nil, fmt.Errorf("received unexpected error when getting status for %q: %w", libDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
modDir := filepath.Join(libDir, kernVer)
|
modDir := filepath.Join(libDir, m.kernVer)
|
||||||
if exists, err := misc.Exists(modDir); !exists {
|
if exists, err := misc.Exists(modDir); !exists {
|
||||||
// dir /lib/modules/<kernel> if kernel built without module support, so just print a message
|
// dir /lib/modules/<kernel> if kernel built without module support, so just print a message
|
||||||
log.Printf("-- kernel module directory not found: %q, not including modules", modDir)
|
log.Printf("-- kernel module directory not found: %q, not including modules", modDir)
|
||||||
|
@@ -3,7 +3,6 @@ package misc
|
|||||||
import (
|
import (
|
||||||
"debug/elf"
|
"debug/elf"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@@ -40,24 +39,6 @@ func getFile(file string, required bool) (files []string, err error) {
|
|||||||
return RemoveDuplicates(files), nil
|
return RemoveDuplicates(files), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file is a symlink we need to do this to prevent an infinite recursion
|
|
||||||
// loop:
|
|
||||||
// Symlinks need special handling to prevent infinite recursion:
|
|
||||||
// 1) add the symlink to the list of files
|
|
||||||
// 2) set file to dereferenced target
|
|
||||||
// 4) continue this function to either walk it if the target is a dir or add the
|
|
||||||
// target to the list of files
|
|
||||||
if s, err := os.Lstat(file); err != nil {
|
|
||||||
return files, err
|
|
||||||
} else if s.Mode()&fs.ModeSymlink != 0 {
|
|
||||||
files = append(files, file)
|
|
||||||
if target, err := filepath.EvalSymlinks(file); err != nil {
|
|
||||||
return files, err
|
|
||||||
} else {
|
|
||||||
file = target
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileInfo, err := os.Stat(file)
|
fileInfo, err := os.Stat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Check if there is a Zstd-compressed version of the file
|
// Check if there is a Zstd-compressed version of the file
|
||||||
|
@@ -1,149 +0,0 @@
|
|||||||
// Copyright 2025 Clayton Craft <clayton@craftyguy.net>
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
package misc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGetFile(t *testing.T) {
|
|
||||||
subtests := []struct {
|
|
||||||
name string
|
|
||||||
setup func(tmpDir string) (inputPath string, expectedFiles []string, err error)
|
|
||||||
required bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "symlink to directory - no infinite recursion",
|
|
||||||
setup: func(tmpDir string) (string, []string, error) {
|
|
||||||
// Create target directory with files
|
|
||||||
targetDir := filepath.Join(tmpDir, "target")
|
|
||||||
if err := os.MkdirAll(targetDir, 0755); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
testFile1 := filepath.Join(targetDir, "file1.txt")
|
|
||||||
testFile2 := filepath.Join(targetDir, "file2.txt")
|
|
||||||
if err := os.WriteFile(testFile1, []byte("content1"), 0644); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(testFile2, []byte("content2"), 0644); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create symlink pointing to target directory
|
|
||||||
symlinkPath := filepath.Join(tmpDir, "symlink")
|
|
||||||
if err := os.Symlink(targetDir, symlinkPath); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := []string{symlinkPath, testFile1, testFile2}
|
|
||||||
return symlinkPath, expected, nil
|
|
||||||
},
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "symlink to file - returns both symlink and target",
|
|
||||||
setup: func(tmpDir string) (string, []string, error) {
|
|
||||||
// Create target file
|
|
||||||
targetFile := filepath.Join(tmpDir, "target.txt")
|
|
||||||
if err := os.WriteFile(targetFile, []byte("content"), 0644); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create symlink pointing to target file
|
|
||||||
symlinkPath := filepath.Join(tmpDir, "symlink.txt")
|
|
||||||
if err := os.Symlink(targetFile, symlinkPath); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := []string{symlinkPath, targetFile}
|
|
||||||
return symlinkPath, expected, nil
|
|
||||||
},
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "regular file",
|
|
||||||
setup: func(tmpDir string) (string, []string, error) {
|
|
||||||
regularFile := filepath.Join(tmpDir, "regular.txt")
|
|
||||||
if err := os.WriteFile(regularFile, []byte("content"), 0644); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := []string{regularFile}
|
|
||||||
return regularFile, expected, nil
|
|
||||||
},
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "regular directory",
|
|
||||||
setup: func(tmpDir string) (string, []string, error) {
|
|
||||||
// Create directory with files
|
|
||||||
dirPath := filepath.Join(tmpDir, "testdir")
|
|
||||||
if err := os.MkdirAll(dirPath, 0755); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
file1 := filepath.Join(dirPath, "file1.txt")
|
|
||||||
file2 := filepath.Join(dirPath, "subdir", "file2.txt")
|
|
||||||
|
|
||||||
if err := os.WriteFile(file1, []byte("content1"), 0644); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
if err := os.MkdirAll(filepath.Dir(file2), 0755); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(file2, []byte("content2"), 0644); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := []string{file1, file2}
|
|
||||||
return dirPath, expected, nil
|
|
||||||
},
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, st := range subtests {
|
|
||||||
t.Run(st.name, func(t *testing.T) {
|
|
||||||
tmpDir := t.TempDir()
|
|
||||||
|
|
||||||
inputPath, expectedFiles, err := st.setup(tmpDir)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("setup failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add timeout protection for infinite recursion test
|
|
||||||
done := make(chan struct{})
|
|
||||||
var files []string
|
|
||||||
var getFileErr error
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer close(done)
|
|
||||||
files, getFileErr = getFile(inputPath, st.required)
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
if getFileErr != nil {
|
|
||||||
t.Fatalf("getFile failed: %v", getFileErr)
|
|
||||||
}
|
|
||||||
case <-time.After(5 * time.Second):
|
|
||||||
t.Fatal("getFile appears to be in infinite recursion (timeout)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort for comparison
|
|
||||||
sort.Strings(expectedFiles)
|
|
||||||
sort.Strings(files)
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(expectedFiles, files) {
|
|
||||||
t.Fatalf("expected: %q, got: %q", expectedFiles, files)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user