From 8dff1cc54a7951ee51786c744aa84e3e6cc8cd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 27 Jan 2020 15:19:32 +0100 Subject: [PATCH] Use ~/.ooniprobe as the home directory (#101) * Use ~/.ooniprobe as the home directory Remove all probe-legacy related to code since there is no more conflict between the two Fixes: ooni/probe#972 * Update .gitignore Co-authored-by: Simone Basso --- internal/legacy/legacy.go | 87 --------------------------------------- ooni.go | 5 --- utils/paths.go | 2 +- 3 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 internal/legacy/legacy.go diff --git a/internal/legacy/legacy.go b/internal/legacy/legacy.go deleted file mode 100644 index 27dac4c..0000000 --- a/internal/legacy/legacy.go +++ /dev/null @@ -1,87 +0,0 @@ -package legacy - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/ooni/probe-cli/utils/homedir" - "github.com/pkg/errors" - "gopkg.in/AlecAivazis/survey.v1" -) - -// HomePath returns the path to the OONI Home -func homePath() (string, error) { - home, err := homedir.Dir() - if err != nil { - return "", err - } - return filepath.Join(home, ".ooni"), nil -} - -// HomeExists returns true if a legacy home exists -func homeExists() (bool, error) { - home, err := homePath() - if err == homedir.ErrNoHomeDir { - return false, nil - } - if err != nil { - return false, err - } - path := filepath.Join(home, "ooniprobe.conf") - if _, err := os.Stat(path); os.IsNotExist(err) { - return false, nil - } - return true, nil -} - -// BackupHome the legacy home directory -func backupHome() error { - home, err := homedir.Dir() - if err != nil { - return errors.Wrap(err, "backing up home") - } - oldPath := filepath.Join(home, ".ooni") - newPath := filepath.Join(home, ".ooni-legacy") - if err := os.Rename(oldPath, newPath); err != nil { - return errors.Wrap(err, "backing up home") - } - return nil -} - -// MaybeMigrateHome prompts the user if we should backup the legacy home -func MaybeMigrateHome() error { - exists, err := homeExists() - if err != nil { - return err - } - if !exists { - return nil - } - home, err := homePath() - if err != nil { - return err - } - logf("We found an existing OONI Probe installation") - chosen := "" - prompt := &survey.Select{ - Message: "Should we:", - Options: []string{"delete it", "back it up"}, - } - survey.AskOne(prompt, &chosen, nil) - if chosen == "delete it" { - if err := os.RemoveAll(home); err != nil { - return err - } - } else { - logf("Backing up ~/.ooni to ~/.ooni-legacy") - if err := backupHome(); err != nil { - return err - } - } - return nil -} - -func logf(s string, v ...interface{}) { - fmt.Printf("%s\n", fmt.Sprintf(s, v...)) -} diff --git a/ooni.go b/ooni.go index 9b814e7..674f51d 100644 --- a/ooni.go +++ b/ooni.go @@ -10,7 +10,6 @@ import ( "github.com/ooni/probe-cli/internal/bindata" "github.com/ooni/probe-cli/internal/database" "github.com/ooni/probe-cli/internal/enginex" - "github.com/ooni/probe-cli/internal/legacy" "github.com/ooni/probe-cli/utils" engine "github.com/ooni/probe-engine" "github.com/pkg/errors" @@ -56,10 +55,6 @@ func (c *Context) Terminate() { func (c *Context) Init(softwareName, softwareVersion string) error { var err error - if err = legacy.MaybeMigrateHome(); err != nil { - return errors.Wrap(err, "migrating home") - } - if err = MaybeInitializeHome(c.Home); err != nil { return err } diff --git a/utils/paths.go b/utils/paths.go index a8c719f..7ffa16f 100644 --- a/utils/paths.go +++ b/utils/paths.go @@ -72,6 +72,6 @@ func GetOONIHome() (string, error) { return "", err } - path := filepath.Join(home, ".ooni") + path := filepath.Join(home, ".ooniprobe") return path, nil }