forked from Silverfish/proton-bridge
fix(GODT-2272): use shorter filename for gRPC file socket.
This commit is contained in:
@ -89,6 +89,6 @@ There are now three types of system folders which Bridge recognises:
|
|||||||
| gluon messages | sata | gluon/backend/store |
|
| gluon messages | sata | gluon/backend/store |
|
||||||
| Update files | data | updates |
|
| Update files | data | updates |
|
||||||
| sentry cache | data | sentry_cache |
|
| sentry cache | data | sentry_cache |
|
||||||
| Mac/Linux File Socket | temp | bridge_{RANDOM_UUID}.sock |
|
| Mac/Linux File Socket | temp | bridge{4_DIGITS} |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -580,10 +581,17 @@ func (s *Service) monitorParentPID() {
|
|||||||
func computeFileSocketPath() (string, error) {
|
func computeFileSocketPath() (string, error) {
|
||||||
tempPath := os.TempDir()
|
tempPath := os.TempDir()
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
path := filepath.Join(tempPath, fmt.Sprintf("bridge_%v.sock", uuid.NewString()))
|
path := filepath.Join(tempPath, fmt.Sprintf("bridge%04d", rand.Intn(10000))) // nolint:gosec
|
||||||
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
|
||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := os.Remove(path); err != nil {
|
||||||
|
logrus.WithField("path", path).WithError(err).Warning("Could not remove existing socket file")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", errors.New("unable to find a suitable file socket in user config folder")
|
return "", errors.New("unable to find a suitable file socket in user config folder")
|
||||||
|
|||||||
Reference in New Issue
Block a user