Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Commit eec7068

Browse files
authored
Resolve symlinks in the cacheDirectory (#87)
1 parent a1537e0 commit eec7068

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

proxy.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ import (
2525
)
2626

2727
var (
28-
proxyAddr = flag.String("proxyAddress", "127.0.0.1:8080", "proxy server listen address (tcp)")
29-
pprofAddr = flag.String("pprofAddr", "", "server listen address for pprof")
30-
cacheDir = flag.String("cacheDirectory", filepath.Join(os.TempDir(), "proxy-cache"), "cache directory location")
31-
didOpenLanguage = flag.String("didOpenLanguage", "", "(HACK) If non-empty, send 'textDocument/didOpen' notifications with the specified language field (e.x. 'python') to the language server for every file.")
32-
jsonrpc2IDRewrite = flag.String("jsonrpc2IDRewrite", "none", "(HACK) Rewrite jsonrpc2 ID. none (default) is no rewriting. string will use a string ID. number will use number ID. Useful for language servers with non-spec complaint JSONRPC2 implementations.")
33-
glob = flag.String("glob", "", "A colon (:) separated list of file globs to sync locally. By default we place all files into the workspace, but some language servers may only look at a subset of files. Specifying this allows us to avoid syncing all files. Note: This is done by basename only.")
34-
trace = flag.Bool("trace", true, "trace logs to stderr")
28+
proxyAddr = flag.String("proxyAddress", "127.0.0.1:8080", "proxy server listen address (tcp)")
29+
pprofAddr = flag.String("pprofAddr", "", "server listen address for pprof")
30+
cacheDir *string
31+
unresolvedCacheDir = flag.String("cacheDirectory", filepath.Join(os.TempDir(), "proxy-cache"), "cache directory location")
32+
didOpenLanguage = flag.String("didOpenLanguage", "", "(HACK) If non-empty, send 'textDocument/didOpen' notifications with the specified language field (e.x. 'python') to the language server for every file.")
33+
jsonrpc2IDRewrite = flag.String("jsonrpc2IDRewrite", "none", "(HACK) Rewrite jsonrpc2 ID. none (default) is no rewriting. string will use a string ID. number will use number ID. Useful for language servers with non-spec complaint JSONRPC2 implementations.")
34+
glob = flag.String("glob", "", "A colon (:) separated list of file globs to sync locally. By default we place all files into the workspace, but some language servers may only look at a subset of files. Specifying this allows us to avoid syncing all files. Note: This is done by basename only.")
35+
trace = flag.Bool("trace", true, "trace logs to stderr")
3536
)
3637

3738
type cloneProxy struct {
@@ -79,6 +80,20 @@ func main() {
7980
log.Fatalf("Invalid jsonrpc2IDRewrite value %q", *jsonrpc2IDRewrite)
8081
}
8182

83+
// Ensure the path exists, otherwise symlinks to it cannot be resolved.
84+
if err := os.MkdirAll(*unresolvedCacheDir, os.ModePerm); err != nil {
85+
log.Fatalf("Error when checking -cacheDirectory=%q to check if it exists: %s", *unresolvedCacheDir, err)
86+
}
87+
88+
// Resolve symlinks to avoid path mismatches in situations where the
89+
// language server resolves symlinks. One example is the Swift language
90+
// server: https://github.com/sourcegraph/sourcegraph/issues/11867
91+
resolvedCacheDir, err := filepath.EvalSymlinks(*unresolvedCacheDir)
92+
if err != nil {
93+
log.Fatalf("Could not resolve symlinks in -cacheDirectory=%q because: %s", *unresolvedCacheDir, err)
94+
}
95+
cacheDir = &resolvedCacheDir
96+
8297
lis, err := net.Listen("tcp", *proxyAddr)
8398
if err != nil {
8499
err = errors.Wrap(err, "setting up proxy listener failed")

0 commit comments

Comments
 (0)