diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index 018221ffcc..3da11f427f 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "sort" "syscall" @@ -31,6 +32,7 @@ import ( "github.com/GoogleContainerTools/kaniko/pkg/util" "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" ) // For testing @@ -155,7 +157,20 @@ func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) { // for example the hashing function that determines if files are equal uses the mtime of the files, // which can lag if sync is not called. Unfortunately there can still be lag if too much data needs // to be flushed or the disk does its own caching/buffering. - syscall.Sync() + if runtime.GOOS == "linux" { + dir, err := os.Open(s.directory) + if err != nil { + return nil, nil, err + } + defer dir.Close() + _, _, errno := syscall.Syscall(unix.SYS_SYNCFS, dir.Fd(), 0, 0) + if errno != 0 { + return nil, nil, errno + } + } else { + // fallback to full page cache sync + syscall.Sync() + } s.l.Snapshot()