summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-18 15:16:05 +0000
committerGitHub <noreply@github.com>2020-12-18 15:16:05 +0000
commit5c6b5ef34905f40562b518799c35be8d06694e65 (patch)
treeca34417ff972421d4956e1e3a4594b6508f2b24d /pkg/bindings
parenta73c76df29a022a05d71c351244fe6e54504edc2 (diff)
parent641272d41107f61d996ed71b6f5905e4287dda5a (diff)
downloadpodman-5c6b5ef34905f40562b518799c35be8d06694e65.tar.gz
podman-5c6b5ef34905f40562b518799c35be8d06694e65.tar.bz2
podman-5c6b5ef34905f40562b518799c35be8d06694e65.zip
Merge pull request #8747 from vrothberg/run-950
remote copy
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/archive.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/pkg/bindings/containers/archive.go b/pkg/bindings/containers/archive.go
new file mode 100644
index 000000000..d1bbc0b95
--- /dev/null
+++ b/pkg/bindings/containers/archive.go
@@ -0,0 +1,92 @@
+package containers
+
+import (
+ "context"
+ "io"
+ "net/http"
+ "net/url"
+
+ "github.com/containers/podman/v2/pkg/bindings"
+ "github.com/containers/podman/v2/pkg/copy"
+ "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/pkg/errors"
+)
+
+// Stat checks if the specified path is on the container. Note that the stat
+// report may be set even in case of an error. This happens when the path
+// resolves to symlink pointing to a non-existent path.
+func Stat(ctx context.Context, nameOrID string, path string) (*entities.ContainerStatReport, error) {
+ conn, err := bindings.GetClient(ctx)
+ if err != nil {
+ return nil, err
+ }
+ params := url.Values{}
+ params.Set("path", path)
+
+ response, err := conn.DoRequest(nil, http.MethodHead, "/containers/%s/archive", params, nil, nameOrID)
+ if err != nil {
+ return nil, err
+ }
+
+ var finalErr error
+ if response.StatusCode == http.StatusNotFound {
+ finalErr = copy.ENOENT
+ } else if response.StatusCode != http.StatusOK {
+ finalErr = errors.New(response.Status)
+ }
+
+ var statReport *entities.ContainerStatReport
+
+ fileInfo, err := copy.ExtractFileInfoFromHeader(&response.Header)
+ if err != nil && finalErr == nil {
+ return nil, err
+ }
+
+ if fileInfo != nil {
+ statReport = &entities.ContainerStatReport{FileInfo: *fileInfo}
+ }
+
+ return statReport, finalErr
+}
+
+func CopyFromArchive(ctx context.Context, nameOrID string, path string, reader io.Reader) (entities.ContainerCopyFunc, error) {
+ conn, err := bindings.GetClient(ctx)
+ if err != nil {
+ return nil, err
+ }
+ params := url.Values{}
+ params.Set("path", path)
+
+ return func() error {
+ response, err := conn.DoRequest(reader, http.MethodPut, "/containers/%s/archive", params, nil, nameOrID)
+ if err != nil {
+ return err
+ }
+ if response.StatusCode != http.StatusOK {
+ return errors.New(response.Status)
+ }
+ return response.Process(nil)
+ }, nil
+}
+
+func CopyToArchive(ctx context.Context, nameOrID string, path string, writer io.Writer) (entities.ContainerCopyFunc, error) {
+ conn, err := bindings.GetClient(ctx)
+ if err != nil {
+ return nil, err
+ }
+ params := url.Values{}
+ params.Set("path", path)
+
+ response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/archive", params, nil, nameOrID)
+ if err != nil {
+ return nil, err
+ }
+ if response.StatusCode != http.StatusOK {
+ return nil, response.Process(nil)
+ }
+
+ return func() error {
+ _, err := io.Copy(writer, response.Body)
+ return err
+ }, nil
+}