Skip to content

Commit

Permalink
Shorten autogenerated scandeps socket name
Browse files Browse the repository at this point in the history
Test: Added unit tests
Bug: b/299624496
Change-Id: I9dec4b681be6c4f1f75151fae6b7d454d1c2faed
GitOrigin-RevId: 792f1633f7b6c8c4712f275f39ec21639f1d391c
  • Loading branch information
bentekkie authored and copybara-github committed Sep 12, 2023
1 parent d9b82ec commit 12f7982
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ func New(ctx context.Context, executor executor, cacheDir string, cacheFileMaxMb
}

// buildAddress generates an address for the depsscanner process to listen on.
// If reproxy is on UNIX and using a UDS address then it will append .despscan.sock
// to that address. Otherwise a random TCP port will be chosen.
// If reproxy is on UNIX and using a UDS address then it will prepend _ds to
// the sock file name. Otherwise a random TCP port will be chosen.
func buildAddress(proxyServerAddress string, openPortFunc func() (int, error)) (string, error) {
address := proxyServerAddress
if ipc.GrpcCxxSupportsUDS && strings.HasPrefix(address, "unix://") {
return address + ".despscan.sock", nil
dir, sockFile := filepath.Split(address[len("unix://"):])
return fmt.Sprintf("unix://%s", filepath.Join(dir, "ds_"+sockFile)), nil
}
if strings.HasPrefix(address, "unix://") || strings.HasPrefix(address, "pipe://") {
address = fmt.Sprintf("%s:0", localhost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,32 @@ func TestBuildAddress(t *testing.T) {
wantAddr string
}{
{
name: "UnixSocketOnUnix",
name: "UnixSocketAbsOnUnix",
platforms: []string{"linux", "darwin"},
serverAddr: "unix://some/dir/somesocket.sock",
serverAddr: "unix:///some/dir/somesocket.sock",
openPortFunc: func() (int, error) { return 111, nil },
wantAddr: "unix:///some/dir/ds_somesocket.sock",
},
{
name: "UnixSocketAbsNoDirsOnUnix",
platforms: []string{"linux", "darwin"},
serverAddr: "unix:///somesocket.sock",
openPortFunc: func() (int, error) { return 111, nil },
wantAddr: "unix:///ds_somesocket.sock",
},
{
name: "UnixSocketRelNoDirsOnUnix",
platforms: []string{"linux", "darwin"},
serverAddr: "unix://somesocket.sock",
openPortFunc: func() (int, error) { return 111, nil },
wantAddr: "unix://ds_somesocket.sock",
},
{
name: "UnixSocketRelOnUnix",
platforms: []string{"linux", "darwin"},
serverAddr: "unix://a/b/somesocket.sock",
openPortFunc: func() (int, error) { return 111, nil },
wantAddr: "unix://some/dir/somesocket.sock.despscan.sock",
wantAddr: "unix://a/b/ds_somesocket.sock",
},
{
name: "UnixSocketOnWindows",
Expand Down

0 comments on commit 12f7982

Please sign in to comment.