|
@@ -277,12 +277,18 @@ func homeEnv() string {
|
277
|
277
|
}
|
278
|
278
|
|
279
|
279
|
// setTmpDir prepares the directory to use to save profiles retrieved
|
280
|
|
-// remotely. It is selected from PPROF_TMPDIR, defaults to $HOME/pprof.
|
|
280
|
+// remotely. It is selected from PPROF_TMPDIR, defaults to $HOME/pprof, and, if
|
|
281
|
+// $HOME is not set, falls back to os.TempDir().
|
281
|
282
|
func setTmpDir(ui plugin.UI) (string, error) {
|
|
283
|
+ var dirs []string
|
282
|
284
|
if profileDir := os.Getenv("PPROF_TMPDIR"); profileDir != "" {
|
283
|
|
- return profileDir, nil
|
|
285
|
+ dirs = append(dirs, profileDir)
|
284
|
286
|
}
|
285
|
|
- for _, tmpDir := range []string{os.Getenv(homeEnv()) + "/pprof", os.TempDir()} {
|
|
287
|
+ if homeDir := os.Getenv(homeEnv()); homeDir != "" {
|
|
288
|
+ dirs = append(dirs, filepath.Join(homeDir, "pprof"))
|
|
289
|
+ }
|
|
290
|
+ dirs = append(dirs, os.TempDir())
|
|
291
|
+ for _, tmpDir := range dirs {
|
286
|
292
|
if err := os.MkdirAll(tmpDir, 0755); err != nil {
|
287
|
293
|
ui.PrintErr("Could not use temp dir ", tmpDir, ": ", err.Error())
|
288
|
294
|
continue
|