docker_cli_cp_from_container_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. package main
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/go-check/check"
  6. )
  7. // docker cp CONTAINER:PATH LOCALPATH
  8. // Try all of the test cases from the archive package which implements the
  9. // internals of `docker cp` and ensure that the behavior matches when actually
  10. // copying to and from containers.
  11. // Basic assumptions about SRC and DST:
  12. // 1. SRC must exist.
  13. // 2. If SRC ends with a trailing separator, it must be a directory.
  14. // 3. DST parent directory must exist.
  15. // 4. If DST exists as a file, it must not end with a trailing separator.
  16. // First get these easy error cases out of the way.
  17. // Test for error when SRC does not exist.
  18. func (s *DockerSuite) TestCpFromErrSrcNotExists(c *check.C) {
  19. cID := makeTestContainer(c, testContainerOptions{})
  20. defer deleteContainer(cID)
  21. tmpDir := getTestDir(c, "test-cp-from-err-src-not-exists")
  22. defer os.RemoveAll(tmpDir)
  23. err := runDockerCp(c, containerCpPath(cID, "file1"), tmpDir)
  24. if err == nil {
  25. c.Fatal("expected IsNotExist error, but got nil instead")
  26. }
  27. if !isCpNotExist(err) {
  28. c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
  29. }
  30. }
  31. // Test for error when SRC ends in a trailing
  32. // path separator but it exists as a file.
  33. func (s *DockerSuite) TestCpFromErrSrcNotDir(c *check.C) {
  34. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  35. defer deleteContainer(cID)
  36. tmpDir := getTestDir(c, "test-cp-from-err-src-not-dir")
  37. defer os.RemoveAll(tmpDir)
  38. err := runDockerCp(c, containerCpPathTrailingSep(cID, "file1"), tmpDir)
  39. if err == nil {
  40. c.Fatal("expected IsNotDir error, but got nil instead")
  41. }
  42. if !isCpNotDir(err) {
  43. c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
  44. }
  45. }
  46. // Test for error when SRC is a valid file or directory,
  47. // bu the DST parent directory does not exist.
  48. func (s *DockerSuite) TestCpFromErrDstParentNotExists(c *check.C) {
  49. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  50. defer deleteContainer(cID)
  51. tmpDir := getTestDir(c, "test-cp-from-err-dst-parent-not-exists")
  52. defer os.RemoveAll(tmpDir)
  53. makeTestContentInDir(c, tmpDir)
  54. // Try with a file source.
  55. srcPath := containerCpPath(cID, "/file1")
  56. dstPath := cpPath(tmpDir, "notExists", "file1")
  57. err := runDockerCp(c, srcPath, dstPath)
  58. if err == nil {
  59. c.Fatal("expected IsNotExist error, but got nil instead")
  60. }
  61. if !isCpNotExist(err) {
  62. c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
  63. }
  64. // Try with a directory source.
  65. srcPath = containerCpPath(cID, "/dir1")
  66. if err := runDockerCp(c, srcPath, dstPath); err == nil {
  67. c.Fatal("expected IsNotExist error, but got nil instead")
  68. }
  69. if !isCpNotExist(err) {
  70. c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
  71. }
  72. }
  73. // Test for error when DST ends in a trailing
  74. // path separator but exists as a file.
  75. func (s *DockerSuite) TestCpFromErrDstNotDir(c *check.C) {
  76. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  77. defer deleteContainer(cID)
  78. tmpDir := getTestDir(c, "test-cp-from-err-dst-not-dir")
  79. defer os.RemoveAll(tmpDir)
  80. makeTestContentInDir(c, tmpDir)
  81. // Try with a file source.
  82. srcPath := containerCpPath(cID, "/file1")
  83. dstPath := cpPathTrailingSep(tmpDir, "file1")
  84. err := runDockerCp(c, srcPath, dstPath)
  85. if err == nil {
  86. c.Fatal("expected IsNotDir error, but got nil instead")
  87. }
  88. if !isCpNotDir(err) {
  89. c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
  90. }
  91. // Try with a directory source.
  92. srcPath = containerCpPath(cID, "/dir1")
  93. if err := runDockerCp(c, srcPath, dstPath); err == nil {
  94. c.Fatal("expected IsNotDir error, but got nil instead")
  95. }
  96. if !isCpNotDir(err) {
  97. c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
  98. }
  99. }
  100. // Check that copying from a container to a local symlink copies to the symlink
  101. // target and does not overwrite the local symlink itself.
  102. func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
  103. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  104. defer deleteContainer(cID)
  105. tmpDir := getTestDir(c, "test-cp-from-err-dst-not-dir")
  106. defer os.RemoveAll(tmpDir)
  107. makeTestContentInDir(c, tmpDir)
  108. // First, copy a file from the container to a symlink to a file. This
  109. // should overwrite the symlink target contents with the source contents.
  110. srcPath := containerCpPath(cID, "/file2")
  111. dstPath := cpPath(tmpDir, "symlinkToFile1")
  112. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  113. c.Fatalf("unexpected error %T: %s", err, err)
  114. }
  115. // The symlink should not have been modified.
  116. if err := symlinkTargetEquals(c, dstPath, "file1"); err != nil {
  117. c.Fatal(err)
  118. }
  119. // The file should have the contents of "file2" now.
  120. if err := fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"); err != nil {
  121. c.Fatal(err)
  122. }
  123. // Next, copy a file from the container to a symlink to a directory. This
  124. // should copy the file into the symlink target directory.
  125. dstPath = cpPath(tmpDir, "symlinkToDir1")
  126. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  127. c.Fatalf("unexpected error %T: %s", err, err)
  128. }
  129. // The symlink should not have been modified.
  130. if err := symlinkTargetEquals(c, dstPath, "dir1"); err != nil {
  131. c.Fatal(err)
  132. }
  133. // The file should have the contents of "file2" now.
  134. if err := fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"); err != nil {
  135. c.Fatal(err)
  136. }
  137. // Next, copy a file from the container to a symlink to a file that does
  138. // not exist (a broken symlink). This should create the target file with
  139. // the contents of the source file.
  140. dstPath = cpPath(tmpDir, "brokenSymlinkToFileX")
  141. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  142. c.Fatalf("unexpected error %T: %s", err, err)
  143. }
  144. // The symlink should not have been modified.
  145. if err := symlinkTargetEquals(c, dstPath, "fileX"); err != nil {
  146. c.Fatal(err)
  147. }
  148. // The file should have the contents of "file2" now.
  149. if err := fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"); err != nil {
  150. c.Fatal(err)
  151. }
  152. // Next, copy a directory from the container to a symlink to a local
  153. // directory. This should copy the directory into the symlink target
  154. // directory and not modify the symlink.
  155. srcPath = containerCpPath(cID, "/dir2")
  156. dstPath = cpPath(tmpDir, "symlinkToDir1")
  157. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  158. c.Fatalf("unexpected error %T: %s", err, err)
  159. }
  160. // The symlink should not have been modified.
  161. if err := symlinkTargetEquals(c, dstPath, "dir1"); err != nil {
  162. c.Fatal(err)
  163. }
  164. // The directory should now contain a copy of "dir2".
  165. if err := fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"); err != nil {
  166. c.Fatal(err)
  167. }
  168. // Next, copy a directory from the container to a symlink to a local
  169. // directory that does not exist (a broken symlink). This should create
  170. // the target as a directory with the contents of the source directory. It
  171. // should not modify the symlink.
  172. dstPath = cpPath(tmpDir, "brokenSymlinkToDirX")
  173. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  174. c.Fatalf("unexpected error %T: %s", err, err)
  175. }
  176. // The symlink should not have been modified.
  177. if err := symlinkTargetEquals(c, dstPath, "dirX"); err != nil {
  178. c.Fatal(err)
  179. }
  180. // The "dirX" directory should now be a copy of "dir2".
  181. if err := fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"); err != nil {
  182. c.Fatal(err)
  183. }
  184. }
  185. // Possibilities are reduced to the remaining 10 cases:
  186. //
  187. // case | srcIsDir | onlyDirContents | dstExists | dstIsDir | dstTrSep | action
  188. // ===================================================================================================
  189. // A | no | - | no | - | no | create file
  190. // B | no | - | no | - | yes | error
  191. // C | no | - | yes | no | - | overwrite file
  192. // D | no | - | yes | yes | - | create file in dst dir
  193. // E | yes | no | no | - | - | create dir, copy contents
  194. // F | yes | no | yes | no | - | error
  195. // G | yes | no | yes | yes | - | copy dir and contents
  196. // H | yes | yes | no | - | - | create dir, copy contents
  197. // I | yes | yes | yes | no | - | error
  198. // J | yes | yes | yes | yes | - | copy dir contents
  199. //
  200. // A. SRC specifies a file and DST (no trailing path separator) doesn't
  201. // exist. This should create a file with the name DST and copy the
  202. // contents of the source file into it.
  203. func (s *DockerSuite) TestCpFromCaseA(c *check.C) {
  204. cID := makeTestContainer(c, testContainerOptions{
  205. addContent: true, workDir: "/root",
  206. })
  207. defer deleteContainer(cID)
  208. tmpDir := getTestDir(c, "test-cp-from-case-a")
  209. defer os.RemoveAll(tmpDir)
  210. srcPath := containerCpPath(cID, "/root/file1")
  211. dstPath := cpPath(tmpDir, "itWorks.txt")
  212. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  213. c.Fatalf("unexpected error %T: %s", err, err)
  214. }
  215. if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
  216. c.Fatal(err)
  217. }
  218. }
  219. // B. SRC specifies a file and DST (with trailing path separator) doesn't
  220. // exist. This should cause an error because the copy operation cannot
  221. // create a directory when copying a single file.
  222. func (s *DockerSuite) TestCpFromCaseB(c *check.C) {
  223. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  224. defer deleteContainer(cID)
  225. tmpDir := getTestDir(c, "test-cp-from-case-b")
  226. defer os.RemoveAll(tmpDir)
  227. srcPath := containerCpPath(cID, "/file1")
  228. dstDir := cpPathTrailingSep(tmpDir, "testDir")
  229. err := runDockerCp(c, srcPath, dstDir)
  230. if err == nil {
  231. c.Fatal("expected DirNotExists error, but got nil instead")
  232. }
  233. if !isCpDirNotExist(err) {
  234. c.Fatalf("expected DirNotExists error, but got %T: %s", err, err)
  235. }
  236. }
  237. // C. SRC specifies a file and DST exists as a file. This should overwrite
  238. // the file at DST with the contents of the source file.
  239. func (s *DockerSuite) TestCpFromCaseC(c *check.C) {
  240. cID := makeTestContainer(c, testContainerOptions{
  241. addContent: true, workDir: "/root",
  242. })
  243. defer deleteContainer(cID)
  244. tmpDir := getTestDir(c, "test-cp-from-case-c")
  245. defer os.RemoveAll(tmpDir)
  246. makeTestContentInDir(c, tmpDir)
  247. srcPath := containerCpPath(cID, "/root/file1")
  248. dstPath := cpPath(tmpDir, "file2")
  249. // Ensure the local file starts with different content.
  250. if err := fileContentEquals(c, dstPath, "file2\n"); err != nil {
  251. c.Fatal(err)
  252. }
  253. if err := runDockerCp(c, srcPath, dstPath); err != nil {
  254. c.Fatalf("unexpected error %T: %s", err, err)
  255. }
  256. if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
  257. c.Fatal(err)
  258. }
  259. }
  260. // D. SRC specifies a file and DST exists as a directory. This should place
  261. // a copy of the source file inside it using the basename from SRC. Ensure
  262. // this works whether DST has a trailing path separator or not.
  263. func (s *DockerSuite) TestCpFromCaseD(c *check.C) {
  264. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  265. defer deleteContainer(cID)
  266. tmpDir := getTestDir(c, "test-cp-from-case-d")
  267. defer os.RemoveAll(tmpDir)
  268. makeTestContentInDir(c, tmpDir)
  269. srcPath := containerCpPath(cID, "/file1")
  270. dstDir := cpPath(tmpDir, "dir1")
  271. dstPath := filepath.Join(dstDir, "file1")
  272. // Ensure that dstPath doesn't exist.
  273. if _, err := os.Stat(dstPath); !os.IsNotExist(err) {
  274. c.Fatalf("did not expect dstPath %q to exist", dstPath)
  275. }
  276. if err := runDockerCp(c, srcPath, dstDir); err != nil {
  277. c.Fatalf("unexpected error %T: %s", err, err)
  278. }
  279. if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
  280. c.Fatal(err)
  281. }
  282. // Now try again but using a trailing path separator for dstDir.
  283. if err := os.RemoveAll(dstDir); err != nil {
  284. c.Fatalf("unable to remove dstDir: %s", err)
  285. }
  286. if err := os.MkdirAll(dstDir, os.FileMode(0755)); err != nil {
  287. c.Fatalf("unable to make dstDir: %s", err)
  288. }
  289. dstDir = cpPathTrailingSep(tmpDir, "dir1")
  290. if err := runDockerCp(c, srcPath, dstDir); err != nil {
  291. c.Fatalf("unexpected error %T: %s", err, err)
  292. }
  293. if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
  294. c.Fatal(err)
  295. }
  296. }
  297. // E. SRC specifies a directory and DST does not exist. This should create a
  298. // directory at DST and copy the contents of the SRC directory into the DST
  299. // directory. Ensure this works whether DST has a trailing path separator or
  300. // not.
  301. func (s *DockerSuite) TestCpFromCaseE(c *check.C) {
  302. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  303. defer deleteContainer(cID)
  304. tmpDir := getTestDir(c, "test-cp-from-case-e")
  305. defer os.RemoveAll(tmpDir)
  306. srcDir := containerCpPath(cID, "dir1")
  307. dstDir := cpPath(tmpDir, "testDir")
  308. dstPath := filepath.Join(dstDir, "file1-1")
  309. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  310. c.Fatalf("unexpected error %T: %s", err, err)
  311. }
  312. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  313. c.Fatal(err)
  314. }
  315. // Now try again but using a trailing path separator for dstDir.
  316. if err := os.RemoveAll(dstDir); err != nil {
  317. c.Fatalf("unable to remove dstDir: %s", err)
  318. }
  319. dstDir = cpPathTrailingSep(tmpDir, "testDir")
  320. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  321. c.Fatalf("unexpected error %T: %s", err, err)
  322. }
  323. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  324. c.Fatal(err)
  325. }
  326. }
  327. // F. SRC specifies a directory and DST exists as a file. This should cause an
  328. // error as it is not possible to overwrite a file with a directory.
  329. func (s *DockerSuite) TestCpFromCaseF(c *check.C) {
  330. cID := makeTestContainer(c, testContainerOptions{
  331. addContent: true, workDir: "/root",
  332. })
  333. defer deleteContainer(cID)
  334. tmpDir := getTestDir(c, "test-cp-from-case-f")
  335. defer os.RemoveAll(tmpDir)
  336. makeTestContentInDir(c, tmpDir)
  337. srcDir := containerCpPath(cID, "/root/dir1")
  338. dstFile := cpPath(tmpDir, "file1")
  339. err := runDockerCp(c, srcDir, dstFile)
  340. if err == nil {
  341. c.Fatal("expected ErrCannotCopyDir error, but got nil instead")
  342. }
  343. if !isCpCannotCopyDir(err) {
  344. c.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err)
  345. }
  346. }
  347. // G. SRC specifies a directory and DST exists as a directory. This should copy
  348. // the SRC directory and all its contents to the DST directory. Ensure this
  349. // works whether DST has a trailing path separator or not.
  350. func (s *DockerSuite) TestCpFromCaseG(c *check.C) {
  351. cID := makeTestContainer(c, testContainerOptions{
  352. addContent: true, workDir: "/root",
  353. })
  354. defer deleteContainer(cID)
  355. tmpDir := getTestDir(c, "test-cp-from-case-g")
  356. defer os.RemoveAll(tmpDir)
  357. makeTestContentInDir(c, tmpDir)
  358. srcDir := containerCpPath(cID, "/root/dir1")
  359. dstDir := cpPath(tmpDir, "dir2")
  360. resultDir := filepath.Join(dstDir, "dir1")
  361. dstPath := filepath.Join(resultDir, "file1-1")
  362. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  363. c.Fatalf("unexpected error %T: %s", err, err)
  364. }
  365. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  366. c.Fatal(err)
  367. }
  368. // Now try again but using a trailing path separator for dstDir.
  369. if err := os.RemoveAll(dstDir); err != nil {
  370. c.Fatalf("unable to remove dstDir: %s", err)
  371. }
  372. if err := os.MkdirAll(dstDir, os.FileMode(0755)); err != nil {
  373. c.Fatalf("unable to make dstDir: %s", err)
  374. }
  375. dstDir = cpPathTrailingSep(tmpDir, "dir2")
  376. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  377. c.Fatalf("unexpected error %T: %s", err, err)
  378. }
  379. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  380. c.Fatal(err)
  381. }
  382. }
  383. // H. SRC specifies a directory's contents only and DST does not exist. This
  384. // should create a directory at DST and copy the contents of the SRC
  385. // directory (but not the directory itself) into the DST directory. Ensure
  386. // this works whether DST has a trailing path separator or not.
  387. func (s *DockerSuite) TestCpFromCaseH(c *check.C) {
  388. cID := makeTestContainer(c, testContainerOptions{addContent: true})
  389. defer deleteContainer(cID)
  390. tmpDir := getTestDir(c, "test-cp-from-case-h")
  391. defer os.RemoveAll(tmpDir)
  392. srcDir := containerCpPathTrailingSep(cID, "dir1") + "."
  393. dstDir := cpPath(tmpDir, "testDir")
  394. dstPath := filepath.Join(dstDir, "file1-1")
  395. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  396. c.Fatalf("unexpected error %T: %s", err, err)
  397. }
  398. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  399. c.Fatal(err)
  400. }
  401. // Now try again but using a trailing path separator for dstDir.
  402. if err := os.RemoveAll(dstDir); err != nil {
  403. c.Fatalf("unable to remove resultDir: %s", err)
  404. }
  405. dstDir = cpPathTrailingSep(tmpDir, "testDir")
  406. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  407. c.Fatalf("unexpected error %T: %s", err, err)
  408. }
  409. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  410. c.Fatal(err)
  411. }
  412. }
  413. // I. SRC specifies a directory's contents only and DST exists as a file. This
  414. // should cause an error as it is not possible to overwrite a file with a
  415. // directory.
  416. func (s *DockerSuite) TestCpFromCaseI(c *check.C) {
  417. cID := makeTestContainer(c, testContainerOptions{
  418. addContent: true, workDir: "/root",
  419. })
  420. defer deleteContainer(cID)
  421. tmpDir := getTestDir(c, "test-cp-from-case-i")
  422. defer os.RemoveAll(tmpDir)
  423. makeTestContentInDir(c, tmpDir)
  424. srcDir := containerCpPathTrailingSep(cID, "/root/dir1") + "."
  425. dstFile := cpPath(tmpDir, "file1")
  426. err := runDockerCp(c, srcDir, dstFile)
  427. if err == nil {
  428. c.Fatal("expected ErrCannotCopyDir error, but got nil instead")
  429. }
  430. if !isCpCannotCopyDir(err) {
  431. c.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err)
  432. }
  433. }
  434. // J. SRC specifies a directory's contents only and DST exists as a directory.
  435. // This should copy the contents of the SRC directory (but not the directory
  436. // itself) into the DST directory. Ensure this works whether DST has a
  437. // trailing path separator or not.
  438. func (s *DockerSuite) TestCpFromCaseJ(c *check.C) {
  439. cID := makeTestContainer(c, testContainerOptions{
  440. addContent: true, workDir: "/root",
  441. })
  442. defer deleteContainer(cID)
  443. tmpDir := getTestDir(c, "test-cp-from-case-j")
  444. defer os.RemoveAll(tmpDir)
  445. makeTestContentInDir(c, tmpDir)
  446. srcDir := containerCpPathTrailingSep(cID, "/root/dir1") + "."
  447. dstDir := cpPath(tmpDir, "dir2")
  448. dstPath := filepath.Join(dstDir, "file1-1")
  449. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  450. c.Fatalf("unexpected error %T: %s", err, err)
  451. }
  452. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  453. c.Fatal(err)
  454. }
  455. // Now try again but using a trailing path separator for dstDir.
  456. if err := os.RemoveAll(dstDir); err != nil {
  457. c.Fatalf("unable to remove dstDir: %s", err)
  458. }
  459. if err := os.MkdirAll(dstDir, os.FileMode(0755)); err != nil {
  460. c.Fatalf("unable to make dstDir: %s", err)
  461. }
  462. dstDir = cpPathTrailingSep(tmpDir, "dir2")
  463. if err := runDockerCp(c, srcDir, dstDir); err != nil {
  464. c.Fatalf("unexpected error %T: %s", err, err)
  465. }
  466. if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
  467. c.Fatal(err)
  468. }
  469. }