mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Revert "allow overwrite in untar"
This reverts commit 5a3d774e56
.
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
This commit is contained in:
parent
f014236791
commit
10d066c9cb
2 changed files with 6 additions and 12 deletions
|
@ -383,8 +383,7 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
|
||||||
// identity (uncompressed), gzip, bzip2, xz.
|
// identity (uncompressed), gzip, bzip2, xz.
|
||||||
// If `dest` does not exist, it is created unless there are multiple entries in `archive`.
|
// If `dest` does not exist, it is created unless there are multiple entries in `archive`.
|
||||||
// In the latter case, an error is returned.
|
// In the latter case, an error is returned.
|
||||||
// If `dest` is an existing file, it gets overwritten.
|
// An other error is returned if `dest` exists but is not a directory, to prevent overwriting.
|
||||||
// If `dest` is an existing directory, its files get merged (with overwrite for conflicting files).
|
|
||||||
func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
if archive == nil {
|
if archive == nil {
|
||||||
return fmt.Errorf("Empty archive")
|
return fmt.Errorf("Empty archive")
|
||||||
|
@ -400,7 +399,7 @@ func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dirs []*tar.Header
|
dirs []*tar.Header
|
||||||
create bool
|
destNotExist bool
|
||||||
multipleEntries bool
|
multipleEntries bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -409,10 +408,9 @@ func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// destination does not exist, so it is assumed it has to be created.
|
// destination does not exist, so it is assumed it has to be created.
|
||||||
create = true
|
destNotExist = true
|
||||||
} else if !fi.IsDir() {
|
} else if !fi.IsDir() {
|
||||||
// destination exists and is not a directory, so it will be overwritten.
|
return fmt.Errorf("Trying to untar to `%s`: exists but not a directory", dest)
|
||||||
create = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through the files in the archive.
|
// Iterate through the files in the archive.
|
||||||
|
@ -427,7 +425,7 @@ func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an error if destination needs to be created and there is more than 1 entry in the tar stream.
|
// Return an error if destination needs to be created and there is more than 1 entry in the tar stream.
|
||||||
if create && multipleEntries {
|
if destNotExist && multipleEntries {
|
||||||
return fmt.Errorf("Trying to untar an archive with multiple entries to an inexistant target `%s`: did you mean `%s` instead?", dest, filepath.Dir(dest))
|
return fmt.Errorf("Trying to untar an archive with multiple entries to an inexistant target `%s`: did you mean `%s` instead?", dest, filepath.Dir(dest))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +445,7 @@ func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
if create {
|
if destNotExist {
|
||||||
path = dest // we are renaming hdr.Name to dest
|
path = dest // we are renaming hdr.Name to dest
|
||||||
} else {
|
} else {
|
||||||
path = filepath.Join(dest, hdr.Name)
|
path = filepath.Join(dest, hdr.Name)
|
||||||
|
@ -467,7 +465,6 @@ func Untar(archive io.Reader, dest string, options *TarOptions) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createTarFile(path, dest, hdr, tr, options == nil || !options.NoLchown); err != nil {
|
if err := createTarFile(path, dest, hdr, tr, options == nil || !options.NoLchown); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,9 +176,6 @@ func TestTarUntarFile(t *testing.T) {
|
||||||
if err := ioutil.WriteFile(path.Join(origin, "before", "file"), []byte("hello world"), 0700); err != nil {
|
if err := ioutil.WriteFile(path.Join(origin, "before", "file"), []byte("hello world"), 0700); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(path.Join(origin, "after", "file2"), []byte("please overwrite me"), 0700); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tar, err := TarWithOptions(path.Join(origin, "before"), &TarOptions{Compression: Uncompressed, Includes: []string{"file"}})
|
tar, err := TarWithOptions(path.Join(origin, "before"), &TarOptions{Compression: Uncompressed, Includes: []string{"file"}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue