mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #14869 from calavera/remove_duplicated_cp_handlers_init
Remove duplicated code parsing parameters for the archiving handlers.
This commit is contained in:
commit
3ee7297b7e
2 changed files with 36 additions and 46 deletions
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -27,3 +28,29 @@ func int64ValueOrZero(r *http.Request, k string) int64 {
|
|||
}
|
||||
return val
|
||||
}
|
||||
|
||||
type archiveOptions struct {
|
||||
name string
|
||||
path string
|
||||
}
|
||||
|
||||
func archiveFormValues(r *http.Request, vars map[string]string) (archiveOptions, error) {
|
||||
if vars == nil {
|
||||
return archiveOptions{}, fmt.Errorf("Missing parameter")
|
||||
}
|
||||
if err := parseForm(r); err != nil {
|
||||
return archiveOptions{}, err
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
path := r.Form.Get("path")
|
||||
|
||||
switch {
|
||||
case name == "":
|
||||
return archiveOptions{}, fmt.Errorf("bad parameter: 'name' cannot be empty")
|
||||
case path == "":
|
||||
return archiveOptions{}, fmt.Errorf("bad parameter: 'path' cannot be empty")
|
||||
}
|
||||
|
||||
return archiveOptions{name, path}, nil
|
||||
}
|
||||
|
|
|
@ -1376,24 +1376,12 @@ func setContainerPathStatHeader(stat *types.ContainerPathStat, header http.Heade
|
|||
}
|
||||
|
||||
func (s *Server) headContainersArchive(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
if err := parseForm(r); err != nil {
|
||||
v, err := archiveFormValues(r, vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
path := r.Form.Get("path")
|
||||
|
||||
switch {
|
||||
case name == "":
|
||||
return fmt.Errorf("bad parameter: 'name' cannot be empty")
|
||||
case path == "":
|
||||
return fmt.Errorf("bad parameter: 'path' cannot be empty")
|
||||
}
|
||||
|
||||
stat, err := s.daemon.ContainerStatPath(name, path)
|
||||
stat, err := s.daemon.ContainerStatPath(v.name, v.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1402,24 +1390,12 @@ func (s *Server) headContainersArchive(version version.Version, w http.ResponseW
|
|||
}
|
||||
|
||||
func (s *Server) getContainersArchive(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
if err := parseForm(r); err != nil {
|
||||
v, err := archiveFormValues(r, vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
path := r.Form.Get("path")
|
||||
|
||||
switch {
|
||||
case name == "":
|
||||
return fmt.Errorf("bad parameter: 'name' cannot be empty")
|
||||
case path == "":
|
||||
return fmt.Errorf("bad parameter: 'path' cannot be empty")
|
||||
}
|
||||
|
||||
tarArchive, stat, err := s.daemon.ContainerArchivePath(name, path)
|
||||
tarArchive, stat, err := s.daemon.ContainerArchivePath(v.name, v.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1436,26 +1412,13 @@ func (s *Server) getContainersArchive(version version.Version, w http.ResponseWr
|
|||
}
|
||||
|
||||
func (s *Server) putContainersArchive(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
if err := parseForm(r); err != nil {
|
||||
v, err := archiveFormValues(r, vars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := vars["name"]
|
||||
path := r.Form.Get("path")
|
||||
|
||||
noOverwriteDirNonDir := boolValue(r, "noOverwriteDirNonDir")
|
||||
|
||||
switch {
|
||||
case name == "":
|
||||
return fmt.Errorf("bad parameter: 'name' cannot be empty")
|
||||
case path == "":
|
||||
return fmt.Errorf("bad parameter: 'path' cannot be empty")
|
||||
}
|
||||
|
||||
return s.daemon.ContainerExtractToDir(name, path, noOverwriteDirNonDir, r.Body)
|
||||
return s.daemon.ContainerExtractToDir(v.name, v.path, noOverwriteDirNonDir, r.Body)
|
||||
}
|
||||
|
||||
func (s *Server) postContainerExecCreate(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
|
Loading…
Add table
Reference in a new issue