Skip to content

Commit

Permalink
Fix creation of configdir in prehook
Browse files Browse the repository at this point in the history
Move prehook dir settings to main to ensure that running the tests
does not result in the configdir being created.
  • Loading branch information
sarcasticadmin authored and martinhpedersen committed Sep 1, 2024
1 parent 5875996 commit 5604eac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 0 additions & 8 deletions internal/prehook/prehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,14 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"time"

"github.com/la5nta/pat/internal/debug"
"github.com/la5nta/pat/internal/directories"
"golang.org/x/sync/errgroup"
)

var ErrConnNotWrapped = errors.New("connection not wrapped for prehook")

func init() {
// Add {config-dir}/prehooks/ to PATH
prehooksPath := filepath.Join(directories.ConfigDir(), "prehooks")
os.Setenv("PATH", fmt.Sprintf(`%s%c%s`, prehooksPath, os.PathListSeparator, os.Getenv("PATH")))
}

type Script struct {
File string
Args []string
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ var fOptions struct {
Listen string
MailboxPath string
ConfigPath string
PrehooksPath string
LogPath string
EventLogPath string
FormsPath string
Expand All @@ -225,11 +226,13 @@ func optionsSet() *pflag.FlagSet {
defaultMBox := filepath.Join(directories.DataDir(), "mailbox")
defaultFormsPath := filepath.Join(directories.DataDir(), "Standard_Forms")
defaultConfigPath := filepath.Join(directories.ConfigDir(), "config.json")
defaultPrehooksPath := filepath.Join(directories.ConfigDir(), "prehooks")
defaultLogPath := filepath.Join(directories.StateDir(), strings.ToLower(buildinfo.AppName+".log"))
defaultEventLogPath := filepath.Join(directories.StateDir(), "eventlog.json")
set.StringVar(&fOptions.MailboxPath, "mbox", defaultMBox, "Path to mailbox directory.")
set.StringVar(&fOptions.FormsPath, "forms", defaultFormsPath, "Path to forms directory.")
set.StringVar(&fOptions.ConfigPath, "config", defaultConfigPath, "Path to config file.")
set.StringVar(&fOptions.PrehooksPath, "prehooks", defaultPrehooksPath, "Path to prehooks")
set.StringVar(&fOptions.LogPath, "log", defaultLogPath, "Path to log file. The file is truncated on each startup.")
set.StringVar(&fOptions.EventLogPath, "event-log", defaultEventLogPath, "Path to event log file.")

Expand Down Expand Up @@ -308,6 +311,8 @@ func main() {
os.Setenv("GZIP_EXPERIMENT", "1")
}

os.Setenv("PATH", fmt.Sprintf(`%s%c%s`, fOptions.PrehooksPath, os.PathListSeparator, os.Getenv("PATH")))

// Parse configuration file
var err error
config, err = LoadConfig(fOptions.ConfigPath, cfg.DefaultConfig)
Expand Down

0 comments on commit 5604eac

Please sign in to comment.