Skip to content

Commit

Permalink
connect: add fix for long socket paths
Browse files Browse the repository at this point in the history
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
  • Loading branch information
better0fdead committed Oct 31, 2022
1 parent 6f52891 commit aa8e215
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cli/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package connector
import (
"fmt"
"net"
"os"
"path/filepath"
"time"

"github.com/tarantool/go-tarantool"
Expand Down Expand Up @@ -37,6 +39,17 @@ 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 140 symbols(limit).
// To support all paths we use relative path with chdir into a directory of socket.
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 {
Expand Down Expand Up @@ -65,8 +78,8 @@ func Connect(opts ConnectOpts) (Connector, error) {

addr := fmt.Sprintf("%s://%s", opts.Network, opts.Address)
conn, err := tarantool.Connect(addr, tarantool.Opts{
User: opts.Username,
Pass: opts.Password,
User: opts.Username,
Pass: opts.Password,
SkipSchema: true, // We don't need a schema for eval requests.
})
if err != nil {
Expand Down

0 comments on commit aa8e215

Please sign in to comment.