Merge branch 'next' into mongo_storage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pwd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -66,10 +67,11 @@ func (p *pwd) InstanceAttachTerminal(instance *types.Instance) error {
|
||||
terms[instance.SessionId][instance.Name] = conn
|
||||
}
|
||||
io.Copy(encoder.Writer(sw), conn)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error {
|
||||
func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, fileName, dest string, url string) error {
|
||||
defer observeAction("InstanceUploadFromUrl", time.Now())
|
||||
log.Printf("Downloading file [%s]\n", url)
|
||||
resp, err := http.Get(url)
|
||||
@@ -81,9 +83,7 @@ func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error
|
||||
return fmt.Errorf("Could not download file [%s]. Status code: %d\n", url, resp.StatusCode)
|
||||
}
|
||||
|
||||
_, fileName := filepath.Split(url)
|
||||
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, "/var/run/pwd/uploads", fileName, resp.Body)
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, dest, fileName, resp.Body)
|
||||
|
||||
if copyErr != nil {
|
||||
return fmt.Errorf("Error while downloading file [%s]. Error: %s\n", url, copyErr)
|
||||
@@ -92,10 +92,36 @@ func (p *pwd) InstanceUploadFromUrl(instance *types.Instance, url string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pwd) InstanceUploadFromReader(instance *types.Instance, fileName string, reader io.Reader) error {
|
||||
func (p *pwd) getInstanceCWD(instance *types.Instance) (string, error) {
|
||||
b := bytes.NewBufferString("")
|
||||
|
||||
if c, err := p.docker.ExecAttach(instance.Name, []string{"bash", "-c", `pwdx $(</var/run/cwd)`}, b); c > 0 {
|
||||
log.Println(b.String())
|
||||
return "", fmt.Errorf("Error %d trying to get CWD", c)
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
cwd := strings.TrimSpace(strings.Split(b.String(), ":")[1])
|
||||
|
||||
return cwd, nil
|
||||
}
|
||||
|
||||
func (p *pwd) InstanceUploadFromReader(instance *types.Instance, fileName, dest string, reader io.Reader) error {
|
||||
defer observeAction("InstanceUploadFromReader", time.Now())
|
||||
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, "/var/run/pwd/uploads", fileName, reader)
|
||||
var finalDest string
|
||||
if filepath.IsAbs(dest) {
|
||||
finalDest = dest
|
||||
} else {
|
||||
if cwd, err := p.getInstanceCWD(instance); err != nil {
|
||||
return err
|
||||
} else {
|
||||
finalDest = fmt.Sprintf("%s/%s", cwd, dest)
|
||||
}
|
||||
}
|
||||
|
||||
copyErr := p.docker.CopyToContainer(instance.Name, finalDest, fileName, reader)
|
||||
|
||||
if copyErr != nil {
|
||||
return fmt.Errorf("Error while uploading file [%s]. Error: %s\n", fileName, copyErr)
|
||||
|
||||
Reference in New Issue
Block a user