Skip to content

Commit 7bb89d4

Browse files
committed
Add warning when skipping symlinks during kit pack
Print a warning log when pack skips including a symlink in order to avoid confusing on missing files in ModelKits. Additionally, use os.Lstat for raw files to avoid following symlinks accidentally. Signed-off-by: Angel Misevski <amisevsk@gmail.com>
1 parent d2d0373 commit 7bb89d4

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

pkg/lib/filesystem/raw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
func saveContentLayerAsRaw(ctx context.Context, localRepo local.LocalRepo, targetPath string, mediaType mediatype.MediaType, ignore ignore.Paths) (ocispec.Descriptor, *artifact.LayerInfo, error) {
3939
targetPath = filepath.Clean(targetPath)
4040

41-
fi, err := os.Stat(targetPath)
41+
fi, err := os.Lstat(targetPath)
4242
if err != nil {
4343
return ocispec.DescriptorEmptyJSON, nil, fmt.Errorf("failed to read file %s: %w", targetPath, err)
4444
}

pkg/lib/filesystem/tar.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,22 @@ func writeLayerToTar(basePath string, ignore ignore.Paths, tarWriter *output.Pro
209209
if file == "." {
210210
return nil
211211
}
212-
// Skip anything that's not a regular file or directory
213-
if !fi.Mode().IsRegular() && !fi.Mode().IsDir() {
214-
return nil
215-
}
216212
// Since we're walking from the context directory, we want to skip irrelevant files (e.g. sibling directories)
217213
if !sameDirTree(basePath, file) {
218214
if fi.IsDir() {
219215
return filepath.SkipDir
220216
}
221217
return nil
222218
}
219+
// Skip anything that's not a regular file or directory
220+
if !fi.Mode().IsRegular() && !fi.Mode().IsDir() {
221+
if fi.Mode()&os.ModeSymlink != 0 {
222+
plog.Logf(output.LogLevelWarn, "Skipping symlink %s (symlinks are not supported)", file)
223+
} else {
224+
plog.Debugf("Skipping file %s (not a regular file)", file)
225+
}
226+
return nil
227+
}
223228

224229
// Check if file should be ignored by the ignorefile/other Kitfile layers
225230
if shouldIgnore, err := ignore.Matches(file, basePath); err != nil {

0 commit comments

Comments
 (0)