Skip to content

Commit

Permalink
Correctly read users' enable_mtime_preservation config (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysullivan authored May 6, 2020
1 parent 972f3eb commit 131eb11
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TEST_TARGETS = [
":files_in_layer_with_files_base",
":files_with_tar_base",
":tar_base",
":tar_with_mtimes_preserved",
":tar_with_files_base",
":tar_with_tar_base",
":tars_in_layer_with_tar_base",
Expand Down
2 changes: 1 addition & 1 deletion container/build_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __enter__(self):
self.compression,
self.root_directory,
self.default_mtime,
False,
self.enable_mtime_preservation,
)
return self

Expand Down
11 changes: 11 additions & 0 deletions container/image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def assertLayerNContains(self, img, n, paths):
with tarfile.open(fileobj=buf, mode='r') as layer:
self.assertTarballContains(layer, paths)

def assertNonZeroMtimesInTopLayer(self, img):
buf = cStringIO.StringIO(img.blob(img.fs_layers()[0]))
with tarfile.open(fileobj=buf, mode='r') as layer:
for member in layer.getmembers():
self.assertNotEqual(member.mtime, 0)

def assertTopLayerContains(self, img, paths):
self.assertLayerNContains(img, 0, paths)

Expand Down Expand Up @@ -98,6 +104,11 @@ def test_tar_base(self):
# Check that this doesn't have a configured entrypoint.
self.assertConfigEqual(img, 'Entrypoint', None)

def test_tar_with_mtimes_preserved(self):
with TestImage('tar_with_mtimes_preserved') as img:
self.assertDigest(img, '2b01c46f6ba7652112154e7fedfb3357b6cbf1d7eaa09cd15143bb74f8f3b617')
self.assertNonZeroMtimesInTopLayer(img)

def test_tar_with_tar_base(self):
with TestImage('tar_with_tar_base') as img:
self.assertDigest(img, '07a2a6a8547551b318b525cf3388a5515060d3cc4354657b8b2e84c8ea6105c9')
Expand Down
7 changes: 7 additions & 0 deletions testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ container_image(
tars = ["one.tar"],
)

container_image(
name = "tar_with_mtimes_preserved",
base = ":tar_base",
enable_mtime_preservation = True,
tars = ["two.tar"],
)

container_image(
name = "tar_with_tar_base",
base = ":tar_base",
Expand Down

0 comments on commit 131eb11

Please sign in to comment.