From 29a02b08ff4bc4ea185f52e88d29b389abb8761b Mon Sep 17 00:00:00 2001 From: Joe Kutner Date: Sun, 26 Jul 2020 14:28:00 -0500 Subject: [PATCH] Move snapshotPathPrefix into a method This allows the value to be determined on the fly, which supports consumers that use Kaniko snaphot as a library and may need to change the value of config.KanikoDir --- pkg/snapshot/snapshot.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index e8523d4e3..dfbc49177 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -33,7 +33,7 @@ import ( ) // For testing -var snapshotPathPrefix = config.KanikoDir +var snapshotPathPrefix = "" // Snapshotter holds the root directory from which to take snapshots, and a list of snapshots taken type Snapshotter struct { @@ -119,7 +119,7 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool) (string, // TakeSnapshotFS takes a snapshot of the filesystem, avoiding directories in the ignorelist, and creates // a tarball of the changed files. func (s *Snapshotter) TakeSnapshotFS() (string, error) { - f, err := ioutil.TempFile(snapshotPathPrefix, "") + f, err := ioutil.TempFile(s.getSnashotPathPrefix(), "") if err != nil { return "", err } @@ -138,6 +138,13 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) { return f.Name(), nil } +func (s *Snapshotter) getSnashotPathPrefix() string { + if snapshotPathPrefix == "" { + return config.KanikoDir + } + return snapshotPathPrefix +} + func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) { logrus.Info("Taking snapshot of full filesystem...")