resolveWorkDir returns the directory a process should start in. Priority: explicit request dir > agent configured dir > $HOME. Falls through when a candidate is empty or does not exist on disk, matching the behavior of SSH sessions.
(requested string)
| 369 | // Falls through when a candidate is empty or does not exist on |
| 370 | // disk, matching the behavior of SSH sessions. |
| 371 | func (m *manager) resolveWorkDir(requested string) string { |
| 372 | if requested != "" { |
| 373 | return requested |
| 374 | } |
| 375 | if m.workingDir != nil { |
| 376 | if dir := m.workingDir(); dir != "" { |
| 377 | if info, err := os.Stat(dir); err == nil && info.IsDir() { |
| 378 | return dir |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | if home, err := os.UserHomeDir(); err == nil { |
| 383 | return home |
| 384 | } |
| 385 | return "" |
| 386 | } |