Просмотр исходного кода

Merge pull request #951 from dotcloud/add-fix

* Builder: correct the behavior of ADD when copying directories.
Solomon Hykes 12 лет назад
Родитель
Сommit
9c8085a0aa
2 измененных файлов с 8 добавлено и 15 удалено
  1. 3 3
      archive.go
  2. 5 12
      docs/sources/use/builder.rst

+ 3 - 3
archive.go

@@ -185,9 +185,9 @@ func CopyWithTar(src, dst string) error {
 	}
 	}
 	// Create the destination
 	// Create the destination
 	var dstDir string
 	var dstDir string
-	if dst[len(dst)-1] == '/' {
-		// The destination ends in /
-		//   --> dst is the holding directory
+	if srcSt.IsDir() || dst[len(dst)-1] == '/' {
+		// The destination ends in /, or the source is a directory
+		//   --> dst is the holding directory and needs to be created for -C
 		dstDir = dst
 		dstDir = dst
 	} else {
 	} else {
 		// The destination doesn't end in /
 		// The destination doesn't end in /

+ 5 - 12
docs/sources/use/builder.rst

@@ -156,22 +156,15 @@ When a directory is copied or unpacked, it has the same behavior as 'tar -x': th
 a) whatever existed at the destination path and b) the contents of the source tree, with conflicts resolved
 a) whatever existed at the destination path and b) the contents of the source tree, with conflicts resolved
 in favor of b on a file-by-file basis.
 in favor of b on a file-by-file basis.
 
 
-If `<src>` is any other kind of file, it is copied individually along with its metadata.
+If `<src>` is any other kind of file, it is copied individually along with its metadata. In this case,
+if `<dst>` ends with a trailing slash '/', it will be considered a directory and the contents of `<src>`
+will be written at `<dst>/base(<src>)`.
+If `<dst>` does not end with a trailing slash, it will be considered a regular file and the contents
+of `<src>` will be written at `<dst>`.
 
 
 If `<dest>` doesn't exist, it is created along with all missing directories in its path. All new
 If `<dest>` doesn't exist, it is created along with all missing directories in its path. All new
 files and directories are created with mode 0700, uid and gid 0.
 files and directories are created with mode 0700, uid and gid 0.
 
 
-If `<dest>` ends with a trailing slash '/', the contents of `<src>` is copied `inside` it.
-For example "ADD foo /usr/src/" creates /usr/src/foo in the container. If `<dest>` already exists,
-it MUST be a directory.
-
-If `<dest>` does not end with a trailing slash '/', the contents of `<src>` is copied `over` it.
-For example "ADD foo /usr/src" creates /usr/src with the contents of the "foo". If `<dest>` already
-exists, it MUST be of the same type as the source.
-
-
-
-
 3. Dockerfile Examples
 3. Dockerfile Examples
 ======================
 ======================