2 Commits
1.0 ... 1.0.x

Author SHA1 Message Date
Clayton Craft
8f53926fb5 getInitfsModules: don't fail if kernel modules dir does not exist
This directory doesn't exist all the time, e.g. if the kernel was built
without modules or no modules were installed for some reason. Assume the
kernel package knows what it is doing and just print a message that
might be helpful if the kernel package ends up not knowing what it is
doing.
2021-09-05 14:23:58 -07:00
Clayton Craft
155a7bc17f stripExts: don't use a cutset when removing extension
I misread what strings.Trim does, the 2nd param is a _cut set_, so this
was removing any occurance any characters in the 2nd param. Since the
file extension is always a suffix, this uses TrimSuffix.

Fixes a bug where 'virtio_blk.ko' was being trimmed to 'virtio_bl'
2021-09-01 11:03:38 -07:00
2 changed files with 5 additions and 2 deletions

View File

@@ -444,7 +444,9 @@ func getInitfsModules(files misc.StringSet, devinfo deviceinfo.DeviceInfo, kerne
modDir := filepath.Join("/lib/modules", kernelVer) modDir := filepath.Join("/lib/modules", kernelVer)
if !exists(modDir) { if !exists(modDir) {
return errors.New("Kernel module directory not found: " + modDir) // 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)
return nil
} }
// modules.* required by modprobe // modules.* required by modprobe
@@ -614,7 +616,7 @@ func stripExts(file string) string {
if filepath.Ext(file) == "" { if filepath.Ext(file) == "" {
break break
} }
file = strings.Trim(file, filepath.Ext(file)) file = strings.TrimSuffix(file, filepath.Ext(file))
} }
return file return file
} }

View File

@@ -15,6 +15,7 @@ func TestStripExts(t *testing.T) {
{"file.tar.gz.xz.zip", "file"}, {"file.tar.gz.xz.zip", "file"},
{"another_file", "another_file"}, {"another_file", "another_file"},
{"a.b.c.d.e.f.g.h.i", "a"}, {"a.b.c.d.e.f.g.h.i", "a"},
{"virtio_blk.ko", "virtio_blk"},
} }
for _, table := range tables { for _, table := range tables {
out := stripExts(table.in) out := stripExts(table.in)