1
0
mirror of https://github.com/moby/moby.git synced 2025-12-09 10:01:25 +03:00

archive: preserve hardlinks in Tar and Untar

* integration test for preserving hardlinks

Signed-off-by: Vincent Batts <vbatts@redhat.com>
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts
2014-09-15 14:45:53 -04:00
parent 006d2334d1
commit f9f8044363
4 changed files with 160 additions and 20 deletions

View File

@@ -101,6 +101,58 @@ func TestCommitNewFile(t *testing.T) {
logDone("commit - commit file and read")
}
func TestCommitHardlink(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
firstOuput, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err)
}
chunks := strings.Split(strings.TrimSpace(firstOuput), " ")
inode := chunks[0]
found := false
for _, chunk := range chunks[1:] {
if chunk == inode {
found = true
break
}
}
if !found {
t.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
}
cmd = exec.Command(dockerBinary, "commit", "hardlinks", "hardlinks")
imageID, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(imageID, err)
}
imageID = strings.Trim(imageID, "\r\n")
cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
secondOuput, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err)
}
chunks = strings.Split(strings.TrimSpace(secondOuput), " ")
inode = chunks[0]
found = false
for _, chunk := range chunks[1:] {
if chunk == inode {
found = true
break
}
}
if !found {
t.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
}
deleteAllContainers()
deleteImages(imageID)
logDone("commit - commit hardlinks")
}
func TestCommitTTY(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
if _, err := runCommand(cmd); err != nil {