You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/12/15 08:45:17 UTC

[camel-k] branch master updated: fix #1136: do not watch remote files in dev mode

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new e6ea9e5  fix #1136: do not watch remote files in dev mode
     new e80eb53  Merge pull request #1146 from nicolaferraro/1136-fix-dev-mode
e6ea9e5 is described below

commit e6ea9e52e1d5a2111ea12a23537888bcb9f3328c
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Sat Dec 14 23:47:35 2019 +0100

    fix #1136: do not watch remote files in dev mode
---
 pkg/cmd/run.go | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 672c3bc..aec29a8 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -125,7 +125,7 @@ func (o *runCmdOptions) validateArgs(_ *cobra.Command, args []string) error {
 	}
 
 	for _, fileName := range args {
-		if !strings.HasPrefix(fileName, "http://") && !strings.HasPrefix(fileName, "https://") {
+		if !isRemoteHTTPFile(fileName) {
 			if _, err := os.Stat(fileName); err != nil && os.IsNotExist(err) {
 				return errors.Wrap(err, "file "+fileName+" does not exist")
 			} else if err != nil {
@@ -265,23 +265,27 @@ func (o *runCmdOptions) waitForIntegrationReady(integration *v1alpha1.Integratio
 
 func (o *runCmdOptions) syncIntegration(c client.Client, sources []string) error {
 	for _, s := range sources {
-		changes, err := sync.File(o.Context, s)
-		if err != nil {
-			return err
-		}
-		go func() {
-			for {
-				select {
-				case <-o.Context.Done():
-					return
-				case <-changes:
-					_, err := o.updateIntegrationCode(c, sources)
-					if err != nil {
-						fmt.Println("Unable to sync integration: ", err.Error())
+		if !isRemoteHTTPFile(s) {
+			changes, err := sync.File(o.Context, s)
+			if err != nil {
+				return err
+			}
+			go func() {
+				for {
+					select {
+					case <-o.Context.Done():
+						return
+					case <-changes:
+						_, err := o.updateIntegrationCode(c, sources)
+						if err != nil {
+							fmt.Println("Unable to sync integration: ", err.Error())
+						}
 					}
 				}
-			}
-		}()
+			}()
+		} else {
+			fmt.Printf("WARNING: the following URL will not be watched for changes: %s\n", s)
+		}
 	}
 
 	return nil
@@ -457,7 +461,7 @@ func (*runCmdOptions) loadData(fileName string, compress bool) (string, error) {
 	var content []byte
 	var err error
 
-	if !strings.HasPrefix(fileName, "http://") && !strings.HasPrefix(fileName, "https://") {
+	if !isRemoteHTTPFile(fileName) {
 		content, err = ioutil.ReadFile(fileName)
 		if err != nil {
 			return "", err
@@ -523,3 +527,7 @@ func (*runCmdOptions) configureTrait(integration *v1alpha1.Integration, config s
 	integration.Spec.Traits[traitID] = spec
 	return nil
 }
+
+func isRemoteHTTPFile(fileName string) bool {
+	return strings.HasPrefix(fileName, "http://") || strings.HasPrefix(fileName, "https://")
+}