Skip to content

Commit

Permalink
make migration configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed Oct 9, 2023
1 parent 4877579 commit 044c556
Showing 1 changed file with 14 additions and 3 deletions.
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

0 comments on commit 044c556

Please sign in to comment.