Skip to content

Commit 28df1dc

Browse files
authored
Add usrmerge linter failure on files in /lib and /lib64 (#2053)
After usrmerge-lib finished (2025-06-23), files are not allowed to be in /lib or /lib64.
1 parent 4946b05 commit 28df1dc

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

pkg/linter/linter.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,16 @@ func parseMelangeYaml(fsys fs.FS) (*config.Configuration, error) {
785785

786786
func usrmergeLinter(ctx context.Context, _ *config.Configuration, _ string, fsys fs.FS) error {
787787
paths := []string{}
788+
dirs := []string{"sbin", "bin", "usr/sbin", "lib", "lib64"}
789+
790+
pathInDir := func(path string, dirs ...string) bool {
791+
for _, d := range dirs {
792+
if path == d || strings.HasPrefix(path, d+"/") {
793+
return true
794+
}
795+
}
796+
return false
797+
}
788798

789799
err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
790800
if err := ctx.Err(); err != nil {
@@ -798,21 +808,19 @@ func usrmergeLinter(ctx context.Context, _ *config.Configuration, _ string, fsys
798808
return filepath.SkipDir
799809
}
800810

801-
// If it's not a directory of interest just skipp the whole tree
802-
if path != "." && !strings.HasPrefix(path, "sbin") && !strings.HasPrefix(path, "bin") && !strings.HasPrefix(path, "usr/sbin") {
803-
if d.IsDir() && path != "usr" {
804-
return filepath.SkipDir
805-
}
811+
// If it's not a directory of interest just skip the whole tree
812+
if !(path == "." || path == "usr" || pathInDir(path, dirs...)) {
813+
return filepath.SkipDir
806814
}
807815

808-
if path == "sbin" || path == "bin" || path == "usr/sbin" {
816+
if slices.Contains(dirs, path) {
809817
if d.IsDir() || d.Type().IsRegular() {
810818
paths = append(paths, path)
811819
return nil
812820
}
813821
}
814822

815-
if strings.HasPrefix(path, "sbin/") || strings.HasPrefix(path, "bin/") || strings.HasPrefix(path, "usr/sbin/") {
823+
if pathInDir(path, dirs...) {
816824
paths = append(paths, path)
817825
}
818826

pkg/linter/linter_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ func TestLinters(t *testing.T) {
211211
dirFunc: mkfile(t, "usr/sbin"),
212212
linter: "usrmerge",
213213
pass: false,
214+
}, {
215+
dirFunc: mkfile(t, "usr/sbin/wark"),
216+
linter: "usrmerge",
217+
pass: false,
218+
}, {
219+
dirFunc: mkfile(t, "lib/libfoo.so.1"),
220+
linter: "usrmerge",
221+
pass: false,
222+
}, {
223+
dirFunc: mkfile(t, "lib64/libfoo64.so.1"),
224+
linter: "usrmerge",
225+
pass: false,
226+
}, {
227+
dirFunc: mkfile(t, "usr/lib/libfoo64.so.1"),
228+
linter: "usrmerge",
229+
pass: true,
214230
}, {
215231
dirFunc: func() string {
216232
d := t.TempDir()

0 commit comments

Comments
 (0)