Created
July 17, 2018 10:30
-
-
Save kadel/e92cf0e209b4615e3ba3ddf8ee612bd3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/cmd/push.go b/cmd/push.go | |
index 636dc8c..07b031d 100644 | |
--- a/cmd/push.go | |
+++ b/cmd/push.go | |
@@ -4,6 +4,7 @@ import ( | |
"fmt" | |
"net/url" | |
"os" | |
+ "path/filepath" | |
"github.com/fatih/color" | |
"github.com/redhat-developer/odo/pkg/application" | |
@@ -77,13 +78,12 @@ var pushCmd = &cobra.Command{ | |
checkError(err, "") | |
} | |
- var path string | |
if sourceType == "local" { | |
- path = fmt.Sprintf("%s/", u.Path) | |
+ err = component.PushLocal(client, componentName, applicationName, u.Path, os.Stdout, []string{}) | |
} else { | |
- path = u.Path | |
+ dir := filepath.Dir(u.Path) | |
+ err = component.PushLocal(client, componentName, applicationName, dir, os.Stdout, []string{u.Path}) | |
} | |
- err = component.PushLocal(client, componentName, applicationName, path, os.Stdout, []string{}) | |
checkError(err, fmt.Sprintf("failed to push component: %v", componentName)) | |
case "git": | |
// currently we don't support changing build type | |
diff --git a/pkg/component/watch.go b/pkg/component/watch.go | |
index 8b3d9df..e0eef31 100644 | |
--- a/pkg/component/watch.go | |
+++ b/pkg/component/watch.go | |
@@ -170,7 +170,17 @@ func WatchAndPush(client *occlient.Client, componentName string, applicationName | |
fmt.Fprintf(out, "File %s changed\n", file) | |
} | |
fmt.Fprintf(out, "Pushing files...\n") | |
- err := PushLocal(client, componentName, applicationName, path, out, changedFiles) | |
+ fileInfo, err := os.Stat(path) | |
+ if err != nil { | |
+ // TODO | |
+ return err | |
+ } | |
+ if fileInfo.IsDir() { | |
+ err = PushLocal(client, componentName, applicationName, path, out, changedFiles) | |
+ } else { | |
+ pathDir := filepath.Dir(path) | |
+ err = PushLocal(client, componentName, applicationName, pathDir, out, []string{path}) | |
+ } | |
if err != nil { | |
// Intentionally not exiting on error here. | |
// We don't want to break watch when push failed, it might be fixed with the next change. | |
diff --git a/pkg/occlient/occlient.go b/pkg/occlient/occlient.go | |
index f1a9c4d..73680f0 100644 | |
--- a/pkg/occlient/occlient.go | |
+++ b/pkg/occlient/occlient.go | |
@@ -1445,24 +1445,6 @@ func isFile(path string) (bool, error) { | |
// copyFiles is list of changed files captured during `odo watch` | |
// localFile is ignored if copyFiles is set | |
func (c *Client) CopyFile(localPath string, targetPodName string, targetPath string, copyFiles []string) error { | |
- if c, _ := isDirectory(localPath); c { | |
- if len(copyFiles) != 0 { | |
- log.Debugf("Copying files %s to pod %s:%s", copyFiles, targetPodName, targetPath) | |
- } else { | |
- | |
- log.Debugf("Copying directory %s to pod %s:%s", localPath, targetPodName, targetPath) | |
- } | |
- } | |
- | |
- if c, _ := isFile(localPath); c { | |
- if len(copyFiles) != 0 { | |
- log.Debugf("Copying file %s to pod %s:%s", copyFiles, targetPodName, targetPath) | |
- } else { | |
- | |
- log.Debugf("Copying file %s to pod %s:%s", localPath, targetPodName, targetPath) | |
- } | |
- } | |
- | |
dest := targetPath + "/" + path.Base(localPath) | |
reader, writer := io.Pipe() | |
// inspired from https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/cp.go#L235 | |
@@ -1475,16 +1457,9 @@ func (c *Client) CopyFile(localPath string, targetPodName string, targetPath str | |
} | |
}() | |
- | |
- var cmdArr []string | |
- | |
- if c, _ := isDirectory(localPath); c { | |
- // Directory | |
- cmdArr = []string{"tar", "xf", "-", "-C", targetPath, "--strip", "1"} | |
- } else { | |
- // Binary | |
- cmdArr = []string{"tar", "xf", "-", "-C", targetPath} | |
- } | |
+ | |
+ cmdArr := []string{"tar", "xf", "-", "-C", targetPath, "--strip", "1"} | |
+ | |
err := c.ExecCMDInContainer(targetPodName, cmdArr, writer, writer, reader, false) | |
if err != nil { | |
return err |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment