mirror of https://github.com/daffainfo/nuclei.git
use go-homedir instead of standard os.userhomedir (#2262)
* use go-homedir instead of standard os.userhomedir * set r.templatesConfig before write attempt to avoid panicdev
parent
04df7244d3
commit
be73fde0db
|
@ -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)
|
||||
|
|
|
@ -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 != "" {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue