filelist: trim whitespace from lines read from files (MR 55)
Fixes issues with leading/trailing whitespaces really messing with mkinitfs
This commit is contained in:
@@ -44,7 +44,7 @@ func (h *HookDirs) List() (*filelist.FileList, error) {
|
||||
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
dir := s.Text()
|
||||
dir := strings.TrimSpace(s.Text())
|
||||
if len(dir) == 0 || strings.HasPrefix(dir, "#") {
|
||||
continue
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ func slurpFiles(fd io.Reader) (*filelist.FileList, error) {
|
||||
|
||||
s := bufio.NewScanner(fd)
|
||||
for s.Scan() {
|
||||
line := s.Text()
|
||||
line := strings.TrimSpace(s.Text())
|
||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
|
@@ -83,7 +83,7 @@ func slurpModules(fd io.Reader, modDir string) (*filelist.FileList, error) {
|
||||
files := filelist.NewFileList()
|
||||
s := bufio.NewScanner(fd)
|
||||
for s.Scan() {
|
||||
line := s.Text()
|
||||
line := strings.TrimSpace(s.Text())
|
||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
@@ -103,8 +103,8 @@ func slurpModules(fd io.Reader, modDir string) (*filelist.FileList, error) {
|
||||
}
|
||||
} else if dir == "" {
|
||||
// item is a module name
|
||||
if modFilelist, err := getModule(s.Text(), modDir); err != nil {
|
||||
return nil, fmt.Errorf("unable to get module file %q: %w", s.Text(), err)
|
||||
if modFilelist, err := getModule(line, modDir); err != nil {
|
||||
return nil, fmt.Errorf("unable to get module file %q: %w", line, err)
|
||||
} else {
|
||||
for _, file := range modFilelist {
|
||||
files.Add(file, file)
|
||||
@@ -188,7 +188,7 @@ func getModuleDeps(modName string, modulesDep io.Reader) ([]string, error) {
|
||||
|
||||
s := bufio.NewScanner(modulesDep)
|
||||
for s.Scan() {
|
||||
line := s.Text()
|
||||
line := strings.TrimSpace(s.Text())
|
||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ func TestStripExts(t *testing.T) {
|
||||
{"another_file", "another_file"},
|
||||
{"a.b.c.d.e.f.g.h.i", "a"},
|
||||
{"virtio_blk.ko", "virtio_blk"},
|
||||
{"virtio_blk.ko ", "virtio_blk"},
|
||||
}
|
||||
for _, table := range tables {
|
||||
out := stripExts(table.in)
|
||||
|
Reference in New Issue
Block a user