Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creation of configdir in prehook #449

Merged
merged 2 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading