fix: Make the fileresolver Support Prefix Match of Files (#3820)

* fix the dpkg files pattern detection

Signed-off-by: Yuntao Hu <victorhu493@gmail.com>

* consider slash before the path is concatenated

Signed-off-by: Yuntao Hu <victorhu493@gmail.com>

* add test

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Yuntao Hu <victorhu493@gmail.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
VictorHuu
2025-04-24 17:38:05 +00:00
committed by GitHub
co-authored by Alex Goodman
parent 5c6c6aa123
commit 9af087d213
8 changed files with 91 additions and 3 deletions
+5 -1
View File
@@ -169,7 +169,11 @@ func (r ChrootContext) ToNativeGlob(chrootPath string) (string, error) {
return "", err
}
parts[0] = strings.TrimRight(responsePath, "/") + "/"
hasSlash := strings.HasSuffix(parts[0], "/")
parts[0] = responsePath
if hasSlash {
parts[0] = strings.TrimRight(parts[0], "/") + "/"
}
return strings.Join(parts, "*"), nil
}
@@ -558,6 +558,16 @@ func TestToNativeGlob(t *testing.T) {
expectedResult: "/cwd/relative/path/**/file*.txt",
expectedError: nil,
},
{
name: "ending with glob",
chrootContext: ChrootContext{
root: "/root",
cwdRelativeToRoot: "/cwd",
},
chrootPath: "/var/lib/dpkg/info/name.*",
expectedResult: "/root/var/lib/dpkg/info/name.*",
expectedError: nil,
},
}
for _, tt := range tests {