From e0dd12505f6ac246aa2ba5a5e56691906ed07f8c Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 8 Apr 2021 16:38:37 +0200 Subject: [PATCH] Normalize paths to forward slashes Signed-off-by: Hidde Beydals --- cmd/flux/bootstrap_git.go | 2 +- cmd/flux/bootstrap_github.go | 6 +++--- cmd/flux/bootstrap_gitlab.go | 4 ++-- cmd/flux/create_kustomization.go | 3 +-- internal/flags/safe_relative_path.go | 5 +++++ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 2d5f381f..a075069e 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -134,7 +134,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { NotificationController: rootArgs.defaults.NotificationController, ManifestFile: rootArgs.defaults.ManifestFile, Timeout: rootArgs.timeout, - TargetPath: gitArgs.path.String(), + TargetPath: gitArgs.path.ToSlash(), ClusterDomain: bootstrapArgs.clusterDomain, TolerationKeys: bootstrapArgs.tolerationKeys, } diff --git a/cmd/flux/bootstrap_github.go b/cmd/flux/bootstrap_github.go index 5f0f594d..c2cb9806 100644 --- a/cmd/flux/bootstrap_github.go +++ b/cmd/flux/bootstrap_github.go @@ -168,7 +168,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { NotificationController: rootArgs.defaults.NotificationController, ManifestFile: rootArgs.defaults.ManifestFile, Timeout: rootArgs.timeout, - TargetPath: githubArgs.path.String(), + TargetPath: githubArgs.path.ToSlash(), ClusterDomain: bootstrapArgs.clusterDomain, TolerationKeys: bootstrapArgs.tolerationKeys, } @@ -180,7 +180,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { secretOpts := sourcesecret.Options{ Name: bootstrapArgs.secretName, Namespace: rootArgs.namespace, - TargetPath: githubArgs.path.String(), + TargetPath: githubArgs.path.ToSlash(), ManifestFile: sourcesecret.MakeDefaultOptions().ManifestFile, } if bootstrapArgs.tokenAuth { @@ -208,7 +208,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { Namespace: rootArgs.namespace, Branch: bootstrapArgs.branch, Secret: bootstrapArgs.secretName, - TargetPath: githubArgs.path.String(), + TargetPath: githubArgs.path.ToSlash(), ManifestFile: sync.MakeDefaultOptions().ManifestFile, GitImplementation: sourceGitArgs.gitImplementation.String(), RecurseSubmodules: bootstrapArgs.recurseSubmodules, diff --git a/cmd/flux/bootstrap_gitlab.go b/cmd/flux/bootstrap_gitlab.go index d66003cf..f35e91c6 100644 --- a/cmd/flux/bootstrap_gitlab.go +++ b/cmd/flux/bootstrap_gitlab.go @@ -181,7 +181,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { NotificationController: rootArgs.defaults.NotificationController, ManifestFile: rootArgs.defaults.ManifestFile, Timeout: rootArgs.timeout, - TargetPath: gitlabArgs.path.String(), + TargetPath: gitlabArgs.path.ToSlash(), ClusterDomain: bootstrapArgs.clusterDomain, TolerationKeys: bootstrapArgs.tolerationKeys, } @@ -224,7 +224,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { Namespace: rootArgs.namespace, Branch: bootstrapArgs.branch, Secret: bootstrapArgs.secretName, - TargetPath: gitlabArgs.path.String(), + TargetPath: gitlabArgs.path.ToSlash(), ManifestFile: sync.MakeDefaultOptions().ManifestFile, GitImplementation: sourceGitArgs.gitImplementation.String(), RecurseSubmodules: bootstrapArgs.recurseSubmodules, diff --git a/cmd/flux/create_kustomization.go b/cmd/flux/create_kustomization.go index fa48272c..2d0f9523 100644 --- a/cmd/flux/create_kustomization.go +++ b/cmd/flux/create_kustomization.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "path/filepath" "strings" "time" @@ -151,7 +150,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { Interval: metav1.Duration{ Duration: createArgs.interval, }, - Path: filepath.ToSlash(kustomizationArgs.path.String()), + Path: kustomizationArgs.path.ToSlash(), Prune: kustomizationArgs.prune, SourceRef: kustomizev1.CrossNamespaceSourceReference{ Kind: kustomizationArgs.source.Kind, diff --git a/internal/flags/safe_relative_path.go b/internal/flags/safe_relative_path.go index b203674f..4a5f78df 100644 --- a/internal/flags/safe_relative_path.go +++ b/internal/flags/safe_relative_path.go @@ -18,6 +18,7 @@ package flags import ( "fmt" + "path/filepath" "strings" securejoin "github.com/cyphar/filepath-securejoin" @@ -29,6 +30,10 @@ func (p *SafeRelativePath) String() string { return string(*p) } +func (p *SafeRelativePath) ToSlash() string { + return filepath.ToSlash(p.String()) +} + func (p *SafeRelativePath) Set(str string) error { // The result of secure joining on a relative base dir is a flattened relative path. cleanP, err := securejoin.SecureJoin("./", strings.TrimSpace(str))