-
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
1 parent
a8fc483
commit 777292a
Showing
16 changed files
with
1,269 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,91 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"errors" | ||
"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") | ||
|
||
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), | ||
) | ||
|
||
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) | ||
|
||
return err | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.