fix(ssh): use /tmp to place control dir on darwin

OpenSSH complains if the control path is too long (>=104)
On Darwin, os.MkdirTemp is too long, use /tmp instead.

ControlPath too long ('/var/folders/v3/5pnzpycs0pzdpytmgfzc7tj80000gn/T/sock-96855798/sock-b677e145501e220cfb5583ba1638a77ffe779df9' >= 104 bytes)

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
This commit is contained in:
Ayman Bagabas 2022-12-15 10:57:39 +03:00
parent 18959fcb22
commit 83fdf8efd5
No known key found for this signature in database
GPG Key ID: 758FD42981CE1778

@ -2,10 +2,10 @@ package ssh
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"syscall"
@ -110,9 +110,14 @@ func findRuntimeDir(osEnv config.Environment) string {
}
func getControlDir(osEnv config.Environment) (string, error) {
tmpdir, pattern := "", "sock-*"
if runtime.GOOS == "darwin" {
// On Darwin, the default temporary directory results in a socket path that's too long.
tmpdir = "/tmp"
}
dir := findRuntimeDir(osEnv)
if dir == "" {
return ioutil.TempDir("", "sock-*")
return os.MkdirTemp(tmpdir, pattern)
}
dir = filepath.Join(dir, "git-lfs")
err := os.Mkdir(dir, 0700)
@ -121,7 +126,7 @@ func getControlDir(osEnv config.Environment) (string, error) {
// os.ErrExist, but that's not available on Go 1.11.
perr, ok := err.(*os.PathError)
if !ok || perr.Err != syscall.EEXIST {
return ioutil.TempDir("", "sock-*")
return os.MkdirTemp(tmpdir, pattern)
}
}
return dir, nil