-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: zhangyue <zy675793960@yeah.net>
- Loading branch information
zhangyue
committed
May 31, 2019
1 parent
fa2723f
commit 5aeb625
Showing
10 changed files
with
633 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/alibaba/pouch/pkg/httputils" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
func (s *Server) putContainersArchive(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
name := mux.Vars(req)["name"] | ||
path := req.FormValue("path") | ||
|
||
if name == "" { | ||
return httputils.NewHTTPError(errors.New("name can't be empty"), http.StatusBadRequest) | ||
} | ||
if path == "" { | ||
return httputils.NewHTTPError(errors.New("path can't be empty"), http.StatusBadRequest) | ||
} | ||
noOverwriteDirNonDir := httputils.BoolValue(req, "noOverwriteDirNonDir") | ||
copyUIDGID := httputils.BoolValue(req, "copyUIDGID") | ||
|
||
return s.ContainerMgr.ExtractToDir(ctx, name, path, copyUIDGID, noOverwriteDirNonDir, req.Body) | ||
} | ||
|
||
func (s *Server) headContainersArchive(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
name := mux.Vars(req)["name"] | ||
path := req.FormValue("path") | ||
|
||
fmt.Print(name) | ||
|
||
if name == "" { | ||
return httputils.NewHTTPError(errors.New("name can't be empty"), http.StatusBadRequest) | ||
} | ||
if path == "" { | ||
return httputils.NewHTTPError(errors.New("path can't be empty"), http.StatusBadRequest) | ||
} | ||
|
||
stat, err := s.ContainerMgr.StatPath(ctx, name, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
statJSON, err := json.Marshal(stat) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rw.Header().Set( | ||
"X-Docker-Container-Path-Stat", | ||
base64.StdEncoding.EncodeToString(statJSON), | ||
) | ||
|
||
rw.WriteHeader(http.StatusOK) | ||
return nil | ||
} | ||
|
||
func (s *Server) getContainersArchive(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
name := mux.Vars(req)["name"] | ||
path := req.FormValue("path") | ||
|
||
if name == "" { | ||
return httputils.NewHTTPError(errors.New("name can't be empty"), http.StatusBadRequest) | ||
} | ||
if path == "" { | ||
return httputils.NewHTTPError(errors.New("path can't be empty"), http.StatusBadRequest) | ||
} | ||
|
||
tarArchive, stat, err := s.ContainerMgr.ArchivePath(ctx, name, path) | ||
if err != nil { | ||
return err | ||
} | ||
defer tarArchive.Close() | ||
|
||
statJSON, err := json.Marshal(stat) | ||
if err != nil { | ||
return err | ||
} | ||
rw.Header().Set( | ||
"X-Docker-Container-Path-Stat", | ||
base64.StdEncoding.EncodeToString(statJSON), | ||
) | ||
|
||
rw.Header().Set("Content-Type", "application/x-tar") | ||
_, err = io.Copy(rw, tarArchive) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
rw.WriteHeader(http.StatusOK) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.