Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/daemon/plist.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ type PlistConfig struct {
}

// DefaultPlistConfig returns a PlistConfig populated from the current environment.
// The pv binary path is resolved from the running executable so the plist works
// regardless of where pv was installed (e.g. ~/.local/bin, /usr/local/bin).
func DefaultPlistConfig() PlistConfig {
pvDir := config.PvDir()

pvBinary := filepath.Join(config.BinDir(), "pv")
if exe, err := os.Executable(); err == nil {
if resolved, err := filepath.EvalSymlinks(exe); err == nil {
pvBinary = resolved
}
}

return PlistConfig{
Label: Label,
PvBinaryPath: filepath.Join(config.BinDir(), "pv"),
PvBinaryPath: pvBinary,
LogDir: config.LogsDir(),
HomeDir: pvDir,
RunAtLoad: false,
Expand Down
4 changes: 2 additions & 2 deletions internal/daemon/plist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func TestDefaultPlistConfig(t *testing.T) {
if cfg.Label != Label {
t.Errorf("Label = %q, want %q", cfg.Label, Label)
}
if !strings.HasSuffix(cfg.PvBinaryPath, filepath.Join(".pv", "bin", "pv")) {
t.Errorf("PvBinaryPath = %q, want suffix .pv/bin/pv", cfg.PvBinaryPath)
if cfg.PvBinaryPath == "" || !filepath.IsAbs(cfg.PvBinaryPath) {
t.Errorf("PvBinaryPath = %q, want non-empty absolute path", cfg.PvBinaryPath)
}
if !strings.HasSuffix(cfg.LogDir, filepath.Join(".pv", "logs")) {
t.Errorf("LogDir = %q, want suffix .pv/logs", cfg.LogDir)
Expand Down
Loading