From 84c85cc3081b19a2722b96f582bb4b73717c8fd3 Mon Sep 17 00:00:00 2001 From: better0fdead Date: Fri, 28 Oct 2022 14:42:06 +0300 Subject: [PATCH] connect: add fix for long socket paths Now relative path is used instead of real for console socket. It is used to prevent console socket path from being too long. Closes #124 --- cli/connector/connector.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cli/connector/connector.go b/cli/connector/connector.go index 6050ea612..bbdc0a882 100644 --- a/cli/connector/connector.go +++ b/cli/connector/connector.go @@ -3,6 +3,8 @@ package connector import ( "fmt" "net" + "os" + "path/filepath" "time" "github.com/tarantool/go-tarantool" @@ -37,6 +39,19 @@ type Connector interface { // Connect connects to the tarantool instance according to options. func Connect(opts ConnectOpts) (Connector, error) { + // It became common that address is longer than 108 symbols(sun_path limit). + // To reduce length of address we use relative path + // with chdir into a directory of socket. + // e.g blablabla/bla/123.sock -> ./123.sock + workDir, err := os.Getwd() + if err != nil { + return nil, err + } + if _, err := os.Stat(opts.Address); err == nil { + os.Chdir(filepath.Dir(opts.Address)) + opts.Address = "./" + filepath.Base(opts.Address) + defer os.Chdir(workDir) + } // Connect to specified address. greetingConn, err := net.Dial(opts.Network, opts.Address) if err != nil {