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

make migration configurable #145

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
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
17 changes: 14 additions & 3 deletions goflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"gopkg.in/yaml.v3"
)

var (
DisableAutoConfigMigration = false
)

// FlagSet is a list of flags for an application
type FlagSet struct {
CaseSensitive bool
Expand Down Expand Up @@ -110,7 +114,9 @@ func (flagSet *FlagSet) Parse() error {

// migrate data from old config dir to new one
// Ref: https://github.com/projectdiscovery/nuclei/issues/3576
flagSet.migrateConfigDir()
if !DisableAutoConfigMigration {
AttemptConfigMigration()
}

// if config file doesn't exist, create one
if !fileutil.FileExists(configFilePath) {
Expand All @@ -126,12 +132,17 @@ func (flagSet *FlagSet) Parse() error {
return nil
}

func (flagSet *FlagSet) migrateConfigDir() {
// AttemptConfigMigration attempts to migrate config from old config dir to new one
// migration condition
// 1. old config dir exists
// 2. new config dir doesn't exist
// 3. old config dir is not same as new config dir
func AttemptConfigMigration() {
// migration condition
// 1. old config dir exists
// 2. new config dir doesn't exist
// 3. old config dir is not same as new config dir

flagSet := FlagSet{} // dummy flagset
toolConfigDir := flagSet.GetToolConfigDir()
if toolConfigDir != oldAppConfigDir && fileutil.FolderExists(oldAppConfigDir) && !fileutil.FolderExists(toolConfigDir) {
_ = fileutil.CreateFolder(toolConfigDir)
Expand Down