mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove duplicated code parsing parameters for the archiving handlers.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
40b922418c
commit
1612ff9726
2 changed files with 36 additions and 46 deletions
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -27,3 +28,29 @@ func int64ValueOrZero(r *http.Request, k string) int64 {
|
||||||
}
|
}
|
||||||
return val
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1365,24 +1365,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 {
|
func (s *Server) headContainersArchive(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if vars == nil {
|
v, err := archiveFormValues(r, vars)
|
||||||
return fmt.Errorf("Missing parameter")
|
if err != nil {
|
||||||
}
|
|
||||||
if err := parseForm(r); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := vars["name"]
|
stat, err := s.daemon.ContainerStatPath(v.name, v.path)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1391,24 +1379,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 {
|
func (s *Server) getContainersArchive(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if vars == nil {
|
v, err := archiveFormValues(r, vars)
|
||||||
return fmt.Errorf("Missing parameter")
|
if err != nil {
|
||||||
}
|
|
||||||
if err := parseForm(r); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := vars["name"]
|
tarArchive, stat, err := s.daemon.ContainerArchivePath(v.name, v.path)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1425,26 +1401,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 {
|
func (s *Server) putContainersArchive(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if vars == nil {
|
v, err := archiveFormValues(r, vars)
|
||||||
return fmt.Errorf("Missing parameter")
|
if err != nil {
|
||||||
}
|
|
||||||
if err := parseForm(r); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := vars["name"]
|
|
||||||
path := r.Form.Get("path")
|
|
||||||
|
|
||||||
noOverwriteDirNonDir := boolValue(r, "noOverwriteDirNonDir")
|
noOverwriteDirNonDir := boolValue(r, "noOverwriteDirNonDir")
|
||||||
|
return s.daemon.ContainerExtractToDir(v.name, v.path, noOverwriteDirNonDir, r.Body)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) postContainerExecCreate(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func (s *Server) postContainerExecCreate(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
|
Loading…
Reference in a new issue