File tree 1 file changed +14
-0
lines changed
gopls/internal/lsp/filecache 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,20 @@ func getCacheDir() string {
180
180
}
181
181
goplsDir := filepath .Join (userDir , "gopls" )
182
182
183
+ // UserCacheDir may return a nonexistent directory
184
+ // (in which case we must create it, which may fail),
185
+ // or it may return a non-writable directory, in
186
+ // which case we should ideally respect the user's express
187
+ // wishes (e.g. XDG_CACHE_HOME) and not write somewhere else.
188
+ // Sadly UserCacheDir doesn't currently let us distinguish
189
+ // such intent from accidental misconfiguraton such as HOME=/
190
+ // in a CI builder. So, we check whether the gopls subdirectory
191
+ // can be created (or already exists) and not fall back to /tmp.
192
+ // See also https://github.com/golang/go/issues/57638.
193
+ if os .MkdirAll (goplsDir , 0700 ) != nil {
194
+ goplsDir = filepath .Join (os .TempDir (), "gopls" )
195
+ }
196
+
183
197
// Start the garbage collector.
184
198
go gc (goplsDir )
185
199
You can’t perform that action at this time.
0 commit comments