mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
* ci: run the full unit suite on windows via make unit Drops the curated `unit:windows` subset; the windows job now bootstraps like linux and runs `make unit`. Exceptions get added as failures show up. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * ci: skip fixture refresh for windows unit tests binny has no windows release, so the bootstrap action can't install the tools the fixture refresh needs. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * test: skip linux container fixtures when docker can't run them Windows CI runners only run windows containers, so image fixtures go through `testutils.SkipWithoutLinuxContainers`. No behavior change on linux/mac. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix: close leaked file handles and posix squashfs paths on windows - output writers are now closed on early returns in `scan`/`convert` (open handles block cleanup on windows) - `newSBOMMultiWriter` used `path.Dir` on host paths, so output subdirectories were never created on windows - squashfs walk paths were built with `filepath.Join` - skip a few posix-only test cases (dir perms, xdg fallback, go-rpmdb ndb handle leak upstream) Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix(golang): resolve go source module dir natively on windows - `parseGoModFile` passed the resolver's posix (`/c/...`) path to the go toolchain, so go source resolution silently found nothing on windows - skip container-built fixtures (go archs, java builds) and golden image tarballs on windows; stereoscope's layer cache filenames contain `:`, which windows rejects Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix: keep posix paths posix on windows - `ChrootContext.ToChrootPath` nested volumes (`D:\cwd\C:\root`) when the scan root was on another drive, so the prefix was never trimmed - bitnami, python wheel/egg, and alpm parsers used `filepath` on posix location paths - alpm backup-file lookups silently missed on windows Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * ci: pull the test fixture cache for windows unit tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix: don't map virtual file tree paths through the host on windows `FiletreeResolver` without a chroot (snaps) ran request paths through `filepath.Abs`, rooting them on the current volume (`/payload.txt` -> `/d/payload.txt`), so snap scans on windows found nothing. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix: match tar entry globs as posix on windows - `matchesAnyGlob` used `doublestar.PathMatch` (host separator) on tar entry names, so tar-wrapped java archives silently produced nothing on windows - test helpers now treat binary snippet keys and `FromFile` locations as posix Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * incorporate windows path fix Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * incorporate go-rpmdb close fix Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * close squashfs fixture writers before finalizing - windows dir listings can report a zero size for files still open, so the manifest was packed empty (also adds a temporary windows diagnostic for the binary cataloger) Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * temp: surface windows binary cataloger diagnostics Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix: keep directory symlink targets posix on windows - the directory indexer joined symlink targets with native separators, so links in the posix file tree pointed nowhere and globs on link names found nothing - binary fixture logical keys used native separators, so nested snippets were picked as the fixture dir on windows Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep addSymlinkToIndex under the funlen limit Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * drop windows skips covered by the stereoscope and go-rpmdb bumps Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
121 lines
2.7 KiB
Go
121 lines
2.7 KiB
Go
package file
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/diskfs/go-diskfs/filesystem"
|
|
)
|
|
|
|
type WalkDiskDirFunc func(fsys filesystem.FileSystem, path string, d os.FileInfo, err error) error
|
|
|
|
// WalkDiskDir walks the file tree within the go-diskfs filesystem at root, calling fn for each file or directory in the tree, including root.
|
|
// This is meant to mimic the behavior of fs.WalkDir in the standard library.
|
|
func WalkDiskDir(fsys filesystem.FileSystem, root string, fn WalkDiskDirFunc) error {
|
|
infos, err := readDiskDir(fsys, root)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(infos) == 0 {
|
|
return nil
|
|
}
|
|
|
|
for _, info := range infos {
|
|
// squashfs paths are posix regardless of host os
|
|
p := path.Join(root, info.Name())
|
|
err = walkDiskDir(fsys, p, info, fn)
|
|
if err != nil {
|
|
if errors.Is(err, fs.SkipDir) {
|
|
continue
|
|
}
|
|
if errors.Is(err, fs.SkipAll) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func walkDiskDir(fsys filesystem.FileSystem, name string, d os.FileInfo, walkDirFn WalkDiskDirFunc) error {
|
|
if err := walkDirFn(fsys, name, d, nil); err != nil {
|
|
if errors.Is(err, fs.SkipDir) && (d == nil || d.IsDir()) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
isDir := d != nil && d.IsDir()
|
|
if d == nil {
|
|
_, err := readDiskDir(fsys, name)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
isDir = true
|
|
}
|
|
|
|
if !isDir {
|
|
return nil
|
|
}
|
|
|
|
dirs, err := readDiskDir(fsys, name)
|
|
if err != nil {
|
|
err = walkDirFn(fsys, name, d, err)
|
|
if err != nil {
|
|
if errors.Is(err, fs.SkipDir) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
for _, d1 := range dirs {
|
|
name1 := path.Join(name, d1.Name())
|
|
if err := walkDiskDir(fsys, name1, d1, walkDirFn); err != nil {
|
|
if errors.Is(err, fs.SkipDir) {
|
|
break
|
|
}
|
|
if errors.Is(err, fs.SkipAll) {
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// readDiskDir reads the directory entries at the given path from a go-diskfs filesystem.
|
|
// go-diskfs returns fs.DirEntry values; these are resolved to os.FileInfo so callers have
|
|
// access to the full file metadata (mode, size, modification time).
|
|
func readDiskDir(fsys filesystem.FileSystem, p string) ([]os.FileInfo, error) {
|
|
entries, err := fsys.ReadDir(ToFSPath(p))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
infos := make([]os.FileInfo, 0, len(entries))
|
|
for _, entry := range entries {
|
|
info, err := entry.Info()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
infos = append(infos, info)
|
|
}
|
|
return infos, nil
|
|
}
|
|
|
|
// ToFSPath converts an absolute ("/"-rooted) path into an io/fs-valid path as required by
|
|
// go-diskfs, where the root is "." and other paths carry no leading slash (see io/fs.ValidPath).
|
|
func ToFSPath(p string) string {
|
|
p = strings.TrimPrefix(p, "/")
|
|
if p == "" {
|
|
return "."
|
|
}
|
|
return p
|
|
}
|