parent
7ae8e7d740
commit
ee95be1e27
|
|
@ -97,6 +97,8 @@ func (t *Tar) AddFileToTar(p string) error {
|
||||||
// this makes this layer unnecessarily differ from a cached layer which does contain this information
|
// this makes this layer unnecessarily differ from a cached layer which does contain this information
|
||||||
hdr.Uname = ""
|
hdr.Uname = ""
|
||||||
hdr.Gname = ""
|
hdr.Gname = ""
|
||||||
|
// use PAX format to preserve accurate mtime (match Docker behavior)
|
||||||
|
hdr.Format = tar.FormatPAX
|
||||||
|
|
||||||
hardlink, linkDst := t.checkHardlink(p, i)
|
hardlink, linkDst := t.checkHardlink(p, i)
|
||||||
if hardlink {
|
if hardlink {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,15 @@ limitations under the License.
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleContainerTools/kaniko/testutil"
|
"github.com/GoogleContainerTools/kaniko/testutil"
|
||||||
)
|
)
|
||||||
|
|
@ -57,6 +60,39 @@ func Test_IsLocalTarArchive(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_AddFileToTar(t *testing.T) {
|
||||||
|
testDir, err := ioutil.TempDir("", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err setting up temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(testDir)
|
||||||
|
|
||||||
|
path := filepath.Join(testDir, regularFiles[0])
|
||||||
|
if err := ioutil.WriteFile(path, []byte("hello"), os.ModePerm); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// use a pre-determined time with non-zero microseconds to avoid flakiness
|
||||||
|
mtime := time.UnixMicro(1635533172891395)
|
||||||
|
if err := os.Chtimes(path, mtime, mtime); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
tarw := NewTar(buf)
|
||||||
|
if err := tarw.AddFileToTar(path); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tarw.Close()
|
||||||
|
|
||||||
|
// Check that the mtime is correct (#1808)
|
||||||
|
tarReader := tar.NewReader(buf)
|
||||||
|
hdr, err := tarReader.Next()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
testutil.CheckDeepEqual(t, mtime, hdr.ModTime)
|
||||||
|
}
|
||||||
|
|
||||||
func setUpFilesAndTars(testDir string) error {
|
func setUpFilesAndTars(testDir string) error {
|
||||||
regularFilesAndContents := map[string]string{
|
regularFilesAndContents := map[string]string{
|
||||||
regularFiles[0]: "",
|
regularFiles[0]: "",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue