Skip to content

Commit 4a91c69

Browse files
authored
Merge pull request #63 from stuartleeks/sl/fix-exec
Fix exec command
2 parents 4a067f5 + 6153df2 commit 4a91c69

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ ENV DEVCONTAINER=true
4545
ENV GO111MODULE=on
4646

4747
# Install Go tools
48+
ARG GO_PLS_VERSION=0.7.2
49+
ARG DLV_VERSION=1.7.2
50+
ARG GO_RELEASER_VERSION=0.180.3
51+
ARG GOLANGCI_LINT_VERSION=1.42.1
4852
RUN \
4953
# --> Delve for debugging
50-
go get github.com/go-delve/delve/cmd/dlv@v1.6.0 \
54+
go get github.com/go-delve/delve/cmd/dlv@v${DLV_VERSION}\
5155
# --> Go language server
52-
&& go get golang.org/x/tools/gopls@v0.6.10 \
56+
&& go get golang.org/x/tools/gopls@v${GO_PLS_VERSION} \
5357
# --> Go symbols and outline for go to symbol support and test support
5458
&& go get github.com/acroca/[email protected] && go get github.com/ramya-rao-a/go-outline@7182a932836a71948db4a81991a494751eccfe77 \
5559
# --> GolangCI-lint
56-
&& curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sed 's/tar -/tar --no-same-owner -/g' | sh -s -- -b $(go env GOPATH)/bin \
60+
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v${GOLANGCI_LINT_VERSION} \
5761
# --> Go releaser
58-
&& curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- "v0.164.0" \
62+
&& curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- v${GO_RELEASER_VERSION} \
5963
# --> Install junit converter
6064
&& go get github.com/jstemmer/[email protected] \
6165
&& sudo rm -rf /go/src/ \

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ require (
66
github.com/blang/semver v3.5.1+incompatible
77
github.com/bradford-hamilton/dora v0.1.1
88
github.com/kyoh86/richgo v0.3.9 // indirect
9-
github.com/mattn/go-isatty v0.0.13 // indirect
9+
github.com/mattn/go-isatty v0.0.14 // indirect
1010
github.com/rhysd/go-github-selfupdate v1.2.2
1111
github.com/spf13/cobra v1.0.0
1212
github.com/spf13/viper v1.4.0
1313
github.com/stretchr/testify v1.7.0
14-
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
14+
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
1515
gopkg.in/yaml.v2 v2.4.0 // indirect
1616
)
1717

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
7777
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
7878
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
7979
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
80+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
81+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
8082
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
8183
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
8284
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
@@ -179,6 +181,8 @@ golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b h1:qh4f65QIVFjq9eBURLEYWqaEX
179181
golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
180182
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
181183
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
184+
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
185+
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
182186
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
183187
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
184188
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

internal/pkg/devcontainers/dockerutils.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func ListDevcontainers() ([]DevcontainerInfo, error) {
7070
}
7171
}
7272
localPath := parts[listPartLocalFolder]
73-
if strings.HasPrefix(localPath, "\\\\wsl$") && wsl.IsWsl() {
73+
if wsl.HasWslPathPrefix(localPath) && wsl.IsWsl() {
7474
localPath, err = wsl.ConvertWindowsPathToWslPath(localPath)
7575
if err != nil {
7676
return []DevcontainerInfo{}, fmt.Errorf("error converting path: %s", err)
@@ -143,7 +143,7 @@ func GetSourceInfoFromDevContainer(containerIDOrName string) (SourceInfo, error)
143143
return SourceInfo{}, err
144144
}
145145

146-
if strings.HasPrefix(localPath, "\\\\wsl$") && wsl.IsWsl() {
146+
if wsl.HasWslPathPrefix(localPath) && wsl.IsWsl() {
147147
localPath, err = wsl.ConvertWindowsPathToWslPath(localPath)
148148
if err != nil {
149149
return SourceInfo{}, fmt.Errorf("error converting path: %s", err)
@@ -165,7 +165,7 @@ func GetSourceInfoFromDevContainer(containerIDOrName string) (SourceInfo, error)
165165
var mount DockerMount
166166
err = json.Unmarshal(output, &mount)
167167
if err != nil {
168-
return SourceInfo{}, fmt.Errorf("failed to get parse JSON getting mount folder for container %q (path=%q): %s", containerIDOrName, mountFolder, err)
168+
return SourceInfo{}, fmt.Errorf("failed to parse JSON getting mount folder for container %q (path=%q): %s", containerIDOrName, mountFolder, err)
169169
}
170170

171171
return SourceInfo{
@@ -199,13 +199,22 @@ func GetClosestPathMatchForPath(devContainers []DevcontainerInfo, devcontainerPa
199199
matchingPaths := byLocalPathLength{}
200200
for _, devcontainer := range devContainers {
201201
// Treat as match if the specified path is within the devcontainer path
202-
if strings.HasPrefix(absPath, devcontainer.LocalFolderPath) {
202+
testPath := devcontainer.LocalFolderPath
203+
if wsl.IsWsl() && wsl.HasWslPathPrefix(testPath) {
204+
testPath, err = wsl.ConvertWindowsPathToWslPath(testPath)
205+
fmt.Println("Converted to..")
206+
if err != nil {
207+
return DevcontainerInfo{}, fmt.Errorf("Error converting path from dev container list (%q): %s", testPath, err)
208+
}
209+
}
210+
if strings.HasPrefix(absPath, testPath) {
203211
matchingPaths = append(matchingPaths, devcontainer)
204212
}
205213
}
206214
if len(matchingPaths) == 0 {
207215
return DevcontainerInfo{}, fmt.Errorf("Could not find running container for path %q", devcontainerPath)
208216
}
217+
209218
// return longest prefix match
210219
sort.Sort(matchingPaths)
211220
return matchingPaths[len(matchingPaths)-1], nil

internal/pkg/devcontainers/remoteuri.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io/ioutil"
77
"path/filepath"
88
"regexp"
9-
"strings"
109

1110
"github.com/stuartleeks/devcontainer-cli/internal/pkg/git"
1211
"github.com/stuartleeks/devcontainer-cli/internal/pkg/wsl"
@@ -49,7 +48,7 @@ func GetWorkspaceMountPath(folderPath string) (string, error) {
4948

5049
// If we're called from WSL we want a WSL Path but will also handle a Windows Path
5150
if wsl.IsWsl() {
52-
if strings.HasPrefix(folderPath, "\\\\wsl$\\") {
51+
if wsl.HasWslPathPrefix(folderPath) {
5352
convertedPath, err := wsl.ConvertWindowsPathToWslPath(folderPath)
5453
if err != nil {
5554
return "", err

internal/pkg/wsl/wsl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ func ConvertWindowsPathToWslPath(path string) (string, error) {
3434
}
3535
return strings.TrimSpace(string(buf)), nil
3636
}
37+
38+
func HasWslPathPrefix(path string) bool {
39+
return strings.HasPrefix(path, "\\\\wsl$\\") || strings.HasPrefix(path, "\\\\wsl.localhost\\")
40+
}

0 commit comments

Comments
 (0)