From 2a359f547c9eeeaae555cdcabc9f64afaf30892d Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 19 Nov 2018 15:56:11 -0500 Subject: [PATCH] Only return filepath.SkipDir for directories From the docs on filepath.SkipDir: > If the function returns SkipDir when invoked on a non-directory file, Walk skips the remaining files in the containing directory This was causing the bug in #457. Since the file `/etc/hosts` was in the whitelist, when filepath.SkipDir was called the entire etc directory was skipped. This change only returns filepath.SkipDir on directories. --- integration/dockerfiles/Dockerfile_test_whitelist | 11 +++++++++++ pkg/snapshot/snapshot.go | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 integration/dockerfiles/Dockerfile_test_whitelist diff --git a/integration/dockerfiles/Dockerfile_test_whitelist b/integration/dockerfiles/Dockerfile_test_whitelist new file mode 100644 index 000000000..80f01d078 --- /dev/null +++ b/integration/dockerfiles/Dockerfile_test_whitelist @@ -0,0 +1,11 @@ +# Make sure that whitelisting (specifically, filepath.SkipDir) works correctly, and that /var/test/testfile and +# /etc/test/testfile end up in the final image + +FROM debian@sha256:38236c068c393272ad02db100e09cac36a5465149e2924a035ee60d6c60c38fe + +RUN mkdir -p /var/test \ + && mkdir -p /etc/test \ + && touch /var/test/testfile \ + && touch /etc/test/testfile \ + && ls -lah /var/test \ + && ls -lah /etc/test; diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index 9e928a46b..8fee12764 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -147,8 +147,11 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) { return err } if util.IsInWhitelist(path) { - logrus.Infof("Skipping paths under %s, as it is a whitelisted directory", path) - return filepath.SkipDir + if util.IsDestDir(path) { + logrus.Infof("Skipping paths under %s, as it is a whitelisted directory", path) + return filepath.SkipDir + } + return nil } memFs[path] = info