Skip to content

Commit 3e89d82

Browse files
authored
Merge pull request #2063 from dmcgowan/cherry-pick-2054
[release/1.0] archive: fix duplicate directories entries on metadata change
2 parents 9016ae9 + 5c21576 commit 3e89d82

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

archive/tar.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,9 @@ func (cw *changeWriter) includeParents(hdr *tar.Header) error {
572572
}
573573
}
574574
}
575+
if hdr.Typeflag == tar.TypeDir {
576+
cw.addedDirs[name] = struct{}{}
577+
}
575578
return nil
576579
}
577580

archive/tar_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ func TestDiffTar(t *testing.T) {
867867
fileEntry("d2/l1", []byte("link me"), 0644),
868868
// d1/f1 and its parent is included after the new link,
869869
// before the new link was included, these files would
870-
// not habe needed
870+
// not have been needed
871871
dirEntry("d1/", 0755),
872872
linkEntry("d1/f1", "d2/l1"),
873873
dirEntry("d3/", 0755),
@@ -898,6 +898,55 @@ func TestDiffTar(t *testing.T) {
898898
fstest.Remove("/d6/l2"),
899899
),
900900
},
901+
{
902+
name: "UpdateDirectoryPermission",
903+
validators: []tarEntryValidator{
904+
dirEntry("d1/", 0777),
905+
dirEntry("d1/d/", 0700),
906+
dirEntry("d2/", 0770),
907+
fileEntry("d2/f", []byte("ok"), 0644),
908+
},
909+
a: fstest.Apply(
910+
fstest.CreateDir("/d1/", 0755),
911+
fstest.CreateDir("/d2/", 0770),
912+
),
913+
b: fstest.Apply(
914+
fstest.Chmod("/d1", 0777),
915+
fstest.CreateDir("/d1/d", 0700),
916+
fstest.CreateFile("/d2/f", []byte("ok"), 0644),
917+
),
918+
},
919+
{
920+
name: "HardlinkUpdatedParent",
921+
validators: []tarEntryValidator{
922+
dirEntry("d1/", 0777),
923+
dirEntry("d2/", 0755),
924+
fileEntry("d2/l1", []byte("link me"), 0644),
925+
// d1/f1 is included after the new link, its
926+
// parent has already changed and therefore
927+
// only the linked file is included
928+
linkEntry("d1/f1", "d2/l1"),
929+
dirEntry("d4/", 0777),
930+
fileEntry("d4/l1", []byte("link me"), 0644),
931+
dirEntry("d3/", 0755),
932+
linkEntry("d3/f1", "d4/l1"),
933+
},
934+
a: fstest.Apply(
935+
fstest.CreateDir("/d1/", 0755),
936+
fstest.CreateFile("/d1/f1", []byte("link me"), 0644),
937+
fstest.CreateDir("/d2/", 0755),
938+
fstest.CreateFile("/d2/f1", []byte("link me"), 0644),
939+
fstest.CreateDir("/d3/", 0755),
940+
fstest.CreateFile("/d3/f1", []byte("link me"), 0644),
941+
fstest.CreateDir("/d4/", 0755),
942+
),
943+
b: fstest.Apply(
944+
fstest.Chmod("/d1", 0777),
945+
fstest.Link("/d1/f1", "/d2/l1"),
946+
fstest.Chmod("/d4", 0777),
947+
fstest.Link("/d3/f1", "/d4/l1"),
948+
),
949+
},
901950
}
902951

903952
for _, at := range tests {

0 commit comments

Comments
 (0)