From 6549675ebc4ba7b0b3177bf2223c45a492e5ecda Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Fri, 27 Feb 2026 06:45:01 +0530 Subject: [PATCH 1/6] fix: exclude OS-specific files from kit init Kitfile generation Filter out OS-generated metadata files (.DS_Store, Thumbs.db, etc.) during directory scanning in kit init to prevent spurious catch-all code layers being added to the generated Kitfile. Signed-off-by: Rishi Jat --- pkg/lib/kitfile/generate/filesystem.go | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkg/lib/kitfile/generate/filesystem.go b/pkg/lib/kitfile/generate/filesystem.go index da8772751..a0ff41812 100644 --- a/pkg/lib/kitfile/generate/filesystem.go +++ b/pkg/lib/kitfile/generate/filesystem.go @@ -20,8 +20,34 @@ import ( "fmt" "os" "path/filepath" + "strings" ) +// osSpecificFiles contains filenames that are auto-generated by operating systems +// and should be ignored during Kitfile generation. +var osSpecificFiles = []string{ + ".DS_Store", // macOS + ".AppleDouble", // macOS + ".LSOverride", // macOS + ".Spotlight-V100", // macOS + ".Trashes", // macOS + "Thumbs.db", // Windows + "desktop.ini", // Windows + "$RECYCLE.BIN", // Windows + "ehthumbs.db", // Windows +} + +// shouldIgnoreFile returns true if the file should be ignored during Kitfile generation. +// This filters out OS-specific metadata files that users did not intentionally create. +func shouldIgnoreFile(name string) bool { + for _, osFile := range osSpecificFiles { + if strings.EqualFold(name, osFile) { + return true + } + } + return false +} + type DirectoryListing struct { Name string Path string @@ -52,6 +78,10 @@ func genDirListingFromPath(curDir, contextDir string) (*DirectoryListing, error) return nil, fmt.Errorf("failed to read directory %s: %w", fullPath, err) } for _, dirEntry := range ds { + // Skip OS-specific files that should not be included in the Kitfile + if shouldIgnoreFile(dirEntry.Name()) { + continue + } relPath := filepath.Join(curDir, dirEntry.Name()) fullPath := filepath.Join(contextDir, relPath) t := dirEntry.Type() From 85b8717a34cf190a78e967dc512a5f031554d217 Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Mon, 16 Mar 2026 05:55:44 +0530 Subject: [PATCH 2/6] refactor: export OS file ignore logic for reuse across kit operations Signed-off-by: Rishi Jat --- pkg/lib/kitfile/generate/filesystem.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/lib/kitfile/generate/filesystem.go b/pkg/lib/kitfile/generate/filesystem.go index a0ff41812..10ae54cde 100644 --- a/pkg/lib/kitfile/generate/filesystem.go +++ b/pkg/lib/kitfile/generate/filesystem.go @@ -23,9 +23,9 @@ import ( "strings" ) -// osSpecificFiles contains filenames that are auto-generated by operating systems -// and should be ignored during Kitfile generation. -var osSpecificFiles = []string{ +// OsSpecificFiles contains filenames that are auto-generated by operating systems +// and should be ignored by KitOps when scanning the filesystem. +var OsSpecificFiles = []string{ ".DS_Store", // macOS ".AppleDouble", // macOS ".LSOverride", // macOS @@ -37,10 +37,11 @@ var osSpecificFiles = []string{ "ehthumbs.db", // Windows } -// shouldIgnoreFile returns true if the file should be ignored during Kitfile generation. -// This filters out OS-specific metadata files that users did not intentionally create. -func shouldIgnoreFile(name string) bool { - for _, osFile := range osSpecificFiles { +// ShouldIgnoreFile returns true if the file should be ignored. +// This helper is exported so other packages (for example packing logic) +// can reuse the same OS-file filtering logic. +func ShouldIgnoreFile(name string) bool { + for _, osFile := range OsSpecificFiles { if strings.EqualFold(name, osFile) { return true } @@ -79,7 +80,7 @@ func genDirListingFromPath(curDir, contextDir string) (*DirectoryListing, error) } for _, dirEntry := range ds { // Skip OS-specific files that should not be included in the Kitfile - if shouldIgnoreFile(dirEntry.Name()) { + if ShouldIgnoreFile(dirEntry.Name()) { continue } relPath := filepath.Join(curDir, dirEntry.Name()) From 50324631c9c4f037356db0625f0c372817465ec4 Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Mon, 16 Mar 2026 06:01:37 +0530 Subject: [PATCH 3/6] fix: ignore hidden and OS-specific files during kit init directory scan Signed-off-by: Rishi Jat --- pkg/lib/kitfile/generate/filesystem.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/lib/kitfile/generate/filesystem.go b/pkg/lib/kitfile/generate/filesystem.go index 10ae54cde..c6afc458a 100644 --- a/pkg/lib/kitfile/generate/filesystem.go +++ b/pkg/lib/kitfile/generate/filesystem.go @@ -41,11 +41,19 @@ var OsSpecificFiles = []string{ // This helper is exported so other packages (for example packing logic) // can reuse the same OS-file filtering logic. func ShouldIgnoreFile(name string) bool { + // Ignore generic hidden files (e.g., .DS_Store, .Spotlight-V100, etc.) + // except for the current and parent directory entries. + if strings.HasPrefix(name, ".") && name != "." && name != ".." { + return true + } + + // Ignore known OS-specific metadata files for _, osFile := range OsSpecificFiles { if strings.EqualFold(name, osFile) { return true } } + return false } From 53e265979160a2b3cb6cc11601813393b785dafb Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Mon, 16 Mar 2026 06:03:47 +0530 Subject: [PATCH 4/6] fix Signed-off-by: Rishi Jat --- pkg/lib/kitfile/generate/filesystem.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/lib/kitfile/generate/filesystem.go b/pkg/lib/kitfile/generate/filesystem.go index c6afc458a..2ec181107 100644 --- a/pkg/lib/kitfile/generate/filesystem.go +++ b/pkg/lib/kitfile/generate/filesystem.go @@ -41,12 +41,6 @@ var OsSpecificFiles = []string{ // This helper is exported so other packages (for example packing logic) // can reuse the same OS-file filtering logic. func ShouldIgnoreFile(name string) bool { - // Ignore generic hidden files (e.g., .DS_Store, .Spotlight-V100, etc.) - // except for the current and parent directory entries. - if strings.HasPrefix(name, ".") && name != "." && name != ".." { - return true - } - // Ignore known OS-specific metadata files for _, osFile := range OsSpecificFiles { if strings.EqualFold(name, osFile) { From 7487281148ddca64b69ffa1cbc7e0b464ae26700 Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Wed, 18 Mar 2026 15:50:48 +0530 Subject: [PATCH 5/6] fix: exclude OS-specific files during layer packing Signed-off-by: Rishi Jat --- pkg/lib/filesystem/local-storage.go | 1 + pkg/lib/filesystem/tar.go | 21 ++++++++++++++++++--- pkg/lib/repo/local/pull.go | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/lib/filesystem/local-storage.go b/pkg/lib/filesystem/local-storage.go index f66828843..14a893f53 100644 --- a/pkg/lib/filesystem/local-storage.go +++ b/pkg/lib/filesystem/local-storage.go @@ -241,6 +241,7 @@ func saveContentLayer(ctx context.Context, localRepo local.LocalRepo, path strin // TODO: Add support for ModelPack's "raw" layer type return ocispec.DescriptorEmptyJSON, nil, fmt.Errorf("Only tar-formatted layers are currently supported") } + tempPath, desc, info, err := packLayerToTar(path, mediaType, ignore) if err != nil { return ocispec.DescriptorEmptyJSON, nil, err diff --git a/pkg/lib/filesystem/tar.go b/pkg/lib/filesystem/tar.go index 06a13c172..db8f5b174 100644 --- a/pkg/lib/filesystem/tar.go +++ b/pkg/lib/filesystem/tar.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "io" + "io/fs" "os" "path/filepath" "strings" @@ -31,6 +32,7 @@ import ( "github.com/kitops-ml/kitops/pkg/lib/constants/mediatype" "github.com/kitops-ml/kitops/pkg/lib/filesystem/cache" "github.com/kitops-ml/kitops/pkg/lib/filesystem/ignore" + "github.com/kitops-ml/kitops/pkg/lib/kitfile/generate" "github.com/kitops-ml/kitops/pkg/output" "github.com/opencontainers/go-digest" @@ -158,7 +160,7 @@ func writeLayerToTar(basePath string, ignore ignore.Paths, tarWriter *output.Pro return true } - err = filepath.Walk(".", func(file string, fi os.FileInfo, err error) error { + err = filepath.WalkDir(".", func(file string, d fs.DirEntry, err error) error { if err != nil { return err } @@ -166,17 +168,30 @@ func writeLayerToTar(basePath string, ignore ignore.Paths, tarWriter *output.Pro return nil } // Skip anything that's not a regular file or directory - if !fi.Mode().IsRegular() && !fi.Mode().IsDir() { + if !d.Type().IsRegular() && !d.IsDir() { return nil } // Since we're walking from the context directory, we want to skip irrelevant files (e.g. sibling directories) if !sameDirTree(basePath, file) { - if fi.IsDir() { + if d.IsDir() { return filepath.SkipDir } return nil } + if generate.ShouldIgnoreFile(d.Name()) { + plog.Debugf("Skipping file %s: OS-specific file", file) + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + + fi, err := d.Info() + if err != nil { + return fmt.Errorf("failed to read file info for %s: %w", file, err) + } + // Check if file should be ignored by the ignorefile/other Kitfile layers if shouldIgnore, err := ignore.Matches(file, basePath); err != nil { return fmt.Errorf("failed to match %s against ignore file: %w", file, err) diff --git a/pkg/lib/repo/local/pull.go b/pkg/lib/repo/local/pull.go index 36b458e58..600502733 100644 --- a/pkg/lib/repo/local/pull.go +++ b/pkg/lib/repo/local/pull.go @@ -29,6 +29,7 @@ import ( "github.com/kitops-ml/kitops/pkg/cmd/options" "github.com/kitops-ml/kitops/pkg/lib/constants" "github.com/kitops-ml/kitops/pkg/lib/constants/mediatype" + "github.com/kitops-ml/kitops/pkg/lib/kitfile/generate" "github.com/kitops-ml/kitops/pkg/lib/repo/util" "github.com/kitops-ml/kitops/pkg/output" @@ -254,6 +255,9 @@ func (l *localRepo) cleanupIngestDir() error { if d.IsDir() { return nil } + if generate.ShouldIgnoreFile(d.Name()) { + return nil + } if err := os.Remove(path); err != nil && !errors.Is(err, fs.ErrNotExist) { return err } From 0a71eb6bc48d5157249d32e810a2f1b45d4a351a Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Fri, 20 Mar 2026 20:21:25 +0530 Subject: [PATCH 6/6] fix Signed-off-by: Rishi Jat --- pkg/lib/repo/local/pull.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/lib/repo/local/pull.go b/pkg/lib/repo/local/pull.go index 600502733..36b458e58 100644 --- a/pkg/lib/repo/local/pull.go +++ b/pkg/lib/repo/local/pull.go @@ -29,7 +29,6 @@ import ( "github.com/kitops-ml/kitops/pkg/cmd/options" "github.com/kitops-ml/kitops/pkg/lib/constants" "github.com/kitops-ml/kitops/pkg/lib/constants/mediatype" - "github.com/kitops-ml/kitops/pkg/lib/kitfile/generate" "github.com/kitops-ml/kitops/pkg/lib/repo/util" "github.com/kitops-ml/kitops/pkg/output" @@ -255,9 +254,6 @@ func (l *localRepo) cleanupIngestDir() error { if d.IsDir() { return nil } - if generate.ShouldIgnoreFile(d.Name()) { - return nil - } if err := os.Remove(path); err != nil && !errors.Is(err, fs.ErrNotExist) { return err }