diff --git a/pkg/client/cli.go b/pkg/client/cli.go index cf12fa079..9b3608192 100644 --- a/pkg/client/cli.go +++ b/pkg/client/cli.go @@ -26,11 +26,9 @@ var ( // forceWriteWithExit is called only when a user passes --write on the command line. func (c *Client) forceWriteWithExit(fileName string) error { - if fileName == "-" { - fileName = c.Flags.ConfigFile - } else if fileName == "example" || fileName == "---" { + if fileName == "example" || fileName == "---" { // Bubilding a default template. - fileName = c.Flags.ConfigFile + fileName = c.Flags.ConfigFile + ".new" c.Config.LogFile = "" c.Config.LogConfig.DebugLog = "" c.Config.HTTPLog = "" @@ -40,8 +38,8 @@ func (c *Client) forceWriteWithExit(fileName string) error { } f, err := c.Config.Write(fileName) - if err != nil { // f purposely shadowed. - return fmt.Errorf("writing config: %s: %w", f, err) + if err != nil { + return fmt.Errorf("writing config: %w", err) } c.Print("Wrote Config File:", f) diff --git a/pkg/configfile/config.go b/pkg/configfile/config.go index e2f419e02..e0144740b 100644 --- a/pkg/configfile/config.go +++ b/pkg/configfile/config.go @@ -204,13 +204,17 @@ func (c *Config) Write(file string) (string, error) { return "", fmt.Errorf("making config dir: %w", err) } - f, err := os.Create(file) + if _, err = os.Stat(file); err == nil { + return "", fmt.Errorf("%w: %s", os.ErrExist, file) + } + + newFile, err := os.Create(file) if err != nil { return "", fmt.Errorf("creating config file: %w", err) } - defer f.Close() + defer newFile.Close() - if err := Template.Execute(f, c); err != nil { + if err := Template.Execute(newFile, c); err != nil { return "", fmt.Errorf("writing config file: %w", err) } diff --git a/pkg/plex/plex.go b/pkg/plex/plex.go index 15c6bcfcc..dd72f6465 100644 --- a/pkg/plex/plex.go +++ b/pkg/plex/plex.go @@ -12,6 +12,7 @@ import ( "fmt" "io/ioutil" "net/http" + "strings" "time" "golift.io/cnfg" @@ -58,6 +59,8 @@ func (s *Server) Configured() bool { // Validate checks input values and starts the cron interval if it's configured. func (s *Server) Validate() { //nolint:cyclop + s.URL = strings.TrimRight(s.URL, "/") + if s.SeriesPC > maximumComplete { s.SeriesPC = maximumComplete } else if s.SeriesPC != 0 && s.SeriesPC < minimumComplete { diff --git a/pkg/services/apps.go b/pkg/services/apps.go index abdcf7a50..861f0fffb 100644 --- a/pkg/services/apps.go +++ b/pkg/services/apps.go @@ -115,7 +115,7 @@ func (c *Config) collectDownloadApps(svcs []*Service) []*Service { svcs = append(svcs, &Service{ Name: d.Name, Type: CheckHTTP, - Value: d.Config.URL, + Value: strings.TrimSuffix(d.Config.URL, "/json"), Expect: "200", Timeout: cnfg.Duration{Duration: d.Timeout.Duration}, Interval: d.Interval,