Skip to content

Commit

Permalink
fix: not copy parent dir when path contains dot
Browse files Browse the repository at this point in the history
Signed-off-by: zhangyue <zy675793960@yeah.net>
  • Loading branch information
zhangyue committed Jun 20, 2019
1 parent 7ff4bc0 commit eb27d2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions daemon/mgr/container_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ func (c *Container) getResolvedPath(path string, running bool) (resolvedPath, ab
}

// get the real path on the host
resolvedPath = filepath.Join(rootfs, absPath)
resolvedPath = filepath.Clean(resolvedPath)
resolvedPath = rootfs + string(os.PathSeparator) + path
cleanedPath := filepath.Clean(resolvedPath)
resolvedPath = archive.PreserveTrailingDotOrSeparator(cleanedPath, resolvedPath, os.PathSeparator)

logrus.Debugf("resolved path: %s", resolvedPath)
return resolvedPath, absPath
}

Expand Down
21 changes: 21 additions & 0 deletions test/cli_container_cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,24 @@ func (suite *PouchContainerCopySuite) TestStopContainerCopy(c *check.C) {
// test stopped container can start after cp
command.PouchRun("start", name).Assert(c, icmd.Success)
}

// Test pouch cp, where path contains dot
func (suite *PouchContainerCopySuite) TestCopyPathDot(c *check.C) {
testDataPath := "testdata/cp/test-copy-path-dot"
c.Assert(os.MkdirAll(testDataPath, 0755), check.IsNil)
defer os.RemoveAll(testDataPath)

name := "TestCopyPathDot"
command.PouchRun("run", "-d",
"--name", name,
busyboxImage,
"sh", "-c",
"mkdir -p test && echo 'test pouch cp' >> test/data.txt && top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)

// don't copy test dir under testDataPath
localTestPath := fmt.Sprintf("%s/%s", testDataPath, "data.txt")
containerTestPath := fmt.Sprintf("%s:%s", name, "test/.")
command.PouchRun("cp", containerTestPath, testDataPath).Assert(c, icmd.Success)
checkFileContains(c, localTestPath, "test pouch cp")
}

0 comments on commit eb27d2b

Please sign in to comment.