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 <bassosimone@gmail.com>
This commit is contained in:
Arturo Filastò 2020-01-27 15:19:32 +01:00 committed by Simone Basso
parent 8d58cb868b
commit 8dff1cc54a
3 changed files with 1 additions and 93 deletions

View File

@ -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...))
}

View File

@ -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
}

View File

@ -72,6 +72,6 @@ func GetOONIHome() (string, error) {
return "", err
}
path := filepath.Join(home, ".ooni")
path := filepath.Join(home, ".ooniprobe")
return path, nil
}