Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not copy parent dir when path contains dot #2920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions daemon/mgr/container_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ 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)

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")
}