Skip to content

Commit d5623b9

Browse files
authored
Merge pull request #72 from stuartleeks/sl/git-sock-update
Update git ipc socket search path
2 parents 8fd324e + 5c62781 commit d5623b9

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

internal/pkg/devcontainers/dockerutils.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,18 @@ func ExecInDevContainer(containerID string, workDir string, args []string) error
285285
fmt.Printf("Warning; Failed to get REMOTE_CONTAINERS_IPC: %s\n", err)
286286
fmt.Println("Continuing without setting REMOTE_CONTAINERS_IPC...")
287287
}
288-
statusWriter.Printf("Getting VSCODE_GIT_IPC_HANDLE")
289-
vscodeGitIpcSock, err := getGitIpcSock(containerID)
290-
if err != nil {
291-
vscodeGitIpcSock = ""
292-
fmt.Printf("Warning; Failed to get VSCODE_GIT_IPC_HANDLE: %s\n", err)
288+
statusWriter.Printf("Getting container User ID")
289+
vscodeGitIpcSock := ""
290+
userID, err := getContainerUserID(containerID, userName)
291+
if err == nil {
292+
statusWriter.Printf("Getting VSCODE_GIT_IPC_HANDLE")
293+
vscodeGitIpcSock, err = getGitIpcSock(containerID, userID)
294+
if err != nil {
295+
fmt.Printf("Warning; Failed to get VSCODE_GIT_IPC_HANDLE: %s\n", err)
296+
fmt.Println("Continuing without setting VSCODE_GIT_IPC_HANDLE...")
297+
}
298+
} else {
299+
fmt.Printf("Warning; Failed to get container User ID: %s\n", err)
293300
fmt.Println("Continuing without setting VSCODE_GIT_IPC_HANDLE...")
294301
}
295302

@@ -395,8 +402,8 @@ func getVscodeIpcSock(containerID string) (string, error) {
395402
func getRemoteContainersIpcSock(containerID string) (string, error) {
396403
return getLatestFileMatch(containerID, "\"${TMPDIR:-/tmp}\"/vscode-remote-containers-ipc-*")
397404
}
398-
func getGitIpcSock(containerID string) (string, error) {
399-
return getLatestFileMatch(containerID, "\"${TMPDIR:-/tmp}\"/vscode-git-*")
405+
func getGitIpcSock(containerID string, userID string) (string, error) {
406+
return getLatestFileMatch(containerID, fmt.Sprintf("\"${TMPDIR:-/tmp}\"/user/%s/vscode-git-*", userID))
400407
}
401408

402409
// getLatestFileMatch lists files matching `pattern` in the container and returns the latest filename
@@ -432,6 +439,25 @@ func getContainerEnvVar(containerID string, varName string) (string, error) {
432439
return string(buf), nil
433440
}
434441

442+
// getContainerUserID gets the UID of the specified user in the container
443+
func getContainerUserID(containerID string, userName string) (string, error) {
444+
445+
dockerArgs := []string{"exec", containerID, "bash", "-c", fmt.Sprintf("id -u %s", userName)}
446+
dockerCmd := exec.Command("docker", dockerArgs...)
447+
buf, err := dockerCmd.CombinedOutput()
448+
if err != nil {
449+
errMessage := string(buf)
450+
return "", fmt.Errorf("Docker exec error: %s (%s)", err, strings.TrimSpace(errMessage))
451+
}
452+
453+
output := string(buf)
454+
lines := strings.Split(output, "\n")
455+
if len(lines) <= 0 {
456+
return "", nil
457+
}
458+
return strings.TrimSpace(lines[0]), nil
459+
}
460+
435461
func testContainerPathExists(containerID string, path string) (bool, error) {
436462
dockerArgs := []string{"exec", containerID, "bash", "-c", fmt.Sprintf("[[ -d %s ]]; echo $?", path)}
437463
dockerCmd := exec.Command("docker", dockerArgs...)

0 commit comments

Comments
 (0)