Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/command/stack/kubernetes/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kubernetes

import (
"io/ioutil"
"path"
"path/filepath"
"sort"

"github.com/docker/cli/kubernetes/compose/v1beta2"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (s *stack) createFileBasedConfigMaps(configMaps corev1.ConfigMapInterface)
continue
}

fileName := path.Base(config.File)
fileName := filepath.Base(config.File)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering; if someone runs in a Bash session on Windows, and/or uses /c/some/path notation (I think that was supported as well in some shells), would this fail?

Should we uses filepath.FromSlash() first (to normalise the input), then filepath.Base?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine, this is what the filepath package takes care of, I believe.
I run everything from Powershell and MinGW64 indifferently and filepath has never failed me.

Given

package main

import (
	"fmt"
	"path/filepath"
)

func base(p string) {
	fmt.Println(filepath.Base(p), p)
}

func main() {
	base("/usr/local/bla")
	base(`\usr\local\bla`)
	base(`C:\usr\local\bla`)
	base("C:/usr/local/bla")
	base(`bla`)
}

Mingw64, Powershell and Cmd all print the same

bla /usr/local/bla
bla \usr\local\bla
bla C:\usr\local\bla
bla C:/usr/local/bla
bla bla

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except, most of them should've printed bla?

If you use, for example, C:/Users/me/somefile, does it work, and is the config read from that file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They all printed bla (first column).
Yes C:/Users/me/somefile yields somefile.
What config are you referring to?

Copy link
Member

@thaJeztah thaJeztah May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh lol, I somehow overlooked the first column, and thought only the last example actually returned bla

What config are you referring to?

sorry, I was typing from my phone so a bit short; Ignore that part, as it's not relevant now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think filepath.FromSlash my be needed here, because filepath.Base is looking for os.PathSeparator. For instance, what happens if the path is /usr/local/bla/?
But I don't have Windows lying around to test this. There should likely be some tests for this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah pointed out that it's looking at os.IsPathSeparator which on Windows accepts both \\ and / as a path separator.

content, err := ioutil.ReadFile(config.File)
if err != nil {
return err
Expand Down Expand Up @@ -76,7 +76,7 @@ func (s *stack) createFileBasedSecrets(secrets corev1.SecretInterface) error {
continue
}

fileName := path.Base(secret.File)
fileName := filepath.Base(secret.File)
content, err := ioutil.ReadFile(secret.File)
if err != nil {
return err
Expand Down