diff --git a/v2/internal/runner/healthcheck.go b/v2/internal/runner/healthcheck.go index d9eb4e7c..b708086e 100644 --- a/v2/internal/runner/healthcheck.go +++ b/v2/internal/runner/healthcheck.go @@ -3,11 +3,11 @@ package runner import ( "fmt" "net" - "os" "path/filepath" "runtime" "strings" + "github.com/mitchellh/go-homedir" "github.com/projectdiscovery/fileutil" "github.com/projectdiscovery/goflags" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/config" @@ -29,7 +29,7 @@ func DoHealthCheck(options *types.Options) string { var testResult string nucleiIgnorePath := filepath.Join(cfgFileFolder, ".nuclei-ignore") - homedir, _ := os.UserHomeDir() + homedir, _ := homedir.Dir() nucleiTemplatePath := filepath.Join(homedir, "nuclei-templates/.checksum") for _, filename := range []string{cfgFilePath, nucleiIgnorePath, nucleiTemplatePath} { ok, err := fileutil.IsReadable(filename) diff --git a/v2/internal/runner/update.go b/v2/internal/runner/update.go index 0d20d9ab..e31cd183 100644 --- a/v2/internal/runner/update.go +++ b/v2/internal/runner/update.go @@ -73,10 +73,10 @@ func (r *Runner) updateTemplates() error { // TODO this method does more than ju TemplatesDirectory: defaultTemplatesDirectory, NucleiVersion: config.Version, } + r.templatesConfig = currentConfig if writeErr := config.WriteConfiguration(currentConfig); writeErr != nil { return errors.Wrap(writeErr, "could not write template configuration") } - r.templatesConfig = currentConfig } if r.options.TemplatesDirectory == "" { if r.templatesConfig.TemplatesDirectory != "" { diff --git a/v2/pkg/catalog/config/config.go b/v2/pkg/catalog/config/config.go index 18c069c8..bf917122 100644 --- a/v2/pkg/catalog/config/config.go +++ b/v2/pkg/catalog/config/config.go @@ -5,6 +5,7 @@ import ( "path/filepath" jsoniter "github.com/json-iterator/go" + "github.com/mitchellh/go-homedir" "github.com/pkg/errors" "gopkg.in/yaml.v2" @@ -41,7 +42,7 @@ func getConfigDetails() (string, error) { // GetConfigDir returns the nuclei configuration directory func GetConfigDir() (string, error) { - home, err := os.UserHomeDir() + home, err := homedir.Dir() if err != nil { return "", err } diff --git a/v2/pkg/utils/template_path.go b/v2/pkg/utils/template_path.go index cb5e7a95..dd68555f 100644 --- a/v2/pkg/utils/template_path.go +++ b/v2/pkg/utils/template_path.go @@ -1,10 +1,10 @@ package utils import ( - "os" "path/filepath" "strings" + "github.com/mitchellh/go-homedir" "github.com/projectdiscovery/nuclei/v2/pkg/catalog/config" ) @@ -35,7 +35,7 @@ func TemplatePathURL(fullPath string) (string, string) { // GetDefaultTemplatePath on default settings func GetDefaultTemplatePath() (string, error) { - home, err := os.UserHomeDir() + home, err := homedir.Dir() if err != nil { return "", err }