diff --git a/cmd/launcher/main.go b/cmd/launcher/main.go index e3bfa19d..b74cd345 100644 --- a/cmd/launcher/main.go +++ b/cmd/launcher/main.go @@ -23,7 +23,6 @@ import ( "path/filepath" "runtime" - "github.com/ProtonMail/go-appdir" "github.com/ProtonMail/gopenpgp/v2/crypto" "github.com/ProtonMail/proton-bridge/internal/constants" "github.com/ProtonMail/proton-bridge/internal/crash" @@ -49,10 +48,12 @@ func main() { // nolint[funlen] crashHandler := crash.NewHandler(sentryReporter.Report) defer crashHandler.HandlePanic() - locations := locations.New( - appdir.New(filepath.Join(constants.VendorName, ConfigName)), - ConfigName, - ) + locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, ConfigName)) + if err != nil { + logrus.WithError(err).Fatal("Failed to get locations provider") + } + + locations := locations.New(locationsProvider, ConfigName) logsPath, err := locations.ProvideLogsPath() if err != nil { diff --git a/go.mod b/go.mod index 09467869..6aafeaf3 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( require ( github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1 github.com/Masterminds/semver/v3 v3.1.0 - github.com/ProtonMail/go-appdir v1.1.0 github.com/ProtonMail/go-apple-mobileconfig v0.0.0-20160701194735-7ea9927a11f6 github.com/ProtonMail/go-autostart v0.0.0-20181114175602-c5272053443a github.com/ProtonMail/go-imap-id v0.0.0-20190926060100-f94a56b9ecde diff --git a/go.sum b/go.sum index 9aaae71f..bfc29b35 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,6 @@ github.com/ProtonMail/crypto v0.0.0-20201112115411-41db4ea0dd1c h1:iaVbEOnskSGgc github.com/ProtonMail/crypto v0.0.0-20201112115411-41db4ea0dd1c/go.mod h1:Pxr7w4gA2ikI4sWyYwEffm+oew1WAJHzG1SiDpQMkrI= github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk= github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g= -github.com/ProtonMail/go-appdir v1.1.0 h1:9hdNDlU9kTqRKVNzmoqah8qqrj5QZyLByQdwQNlFWig= -github.com/ProtonMail/go-appdir v1.1.0/go.mod h1:3d8Y9F5mbEUjrYbcJ3rcDxcWbqbttF+011nVZmdRdzc= github.com/ProtonMail/go-apple-mobileconfig v0.0.0-20160701194735-7ea9927a11f6 h1:YsSJ/mvZFYydQm/hRrt8R8UtgETixN2y3LK98f5LT60= github.com/ProtonMail/go-apple-mobileconfig v0.0.0-20160701194735-7ea9927a11f6/go.mod h1:EtDfBMIDWmVe4viZCuBTEfe3OIIo0ghbpOaAZVO+hVg= github.com/ProtonMail/go-autostart v0.0.0-20181114175602-c5272053443a h1:fXK2KsfnkBV9Nh+9SKzHchYjuE9s0vI20JG1mbtEAcc= diff --git a/internal/app/base/base.go b/internal/app/base/base.go index 7ce454d5..37afd7c5 100644 --- a/internal/app/base/base.go +++ b/internal/app/base/base.go @@ -35,7 +35,6 @@ import ( "runtime/pprof" "github.com/Masterminds/semver/v3" - "github.com/ProtonMail/go-appdir" "github.com/ProtonMail/go-autostart" "github.com/ProtonMail/gopenpgp/v2/crypto" "github.com/ProtonMail/proton-bridge/internal/api" @@ -99,10 +98,12 @@ func New( // nolint[funlen] ) defer crashHandler.HandlePanic() - locations := locations.New( - appdir.New(filepath.Join(constants.VendorName, configName)), - configName, - ) + locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, configName)) + if err != nil { + return nil, err + } + + locations := locations.New(locationsProvider, configName) if err := locations.Clean(); err != nil { return nil, err } diff --git a/internal/app/base/migration.go b/internal/app/base/migration.go index 8e09fcaa..e507781e 100644 --- a/internal/app/base/migration.go +++ b/internal/app/base/migration.go @@ -21,7 +21,6 @@ import ( "os" "path/filepath" - "github.com/ProtonMail/go-appdir" "github.com/ProtonMail/proton-bridge/internal/constants" "github.com/ProtonMail/proton-bridge/internal/locations" "github.com/sirupsen/logrus" @@ -35,10 +34,13 @@ import ( // | prefs | ~/.cache/protonmail//c11/prefs.json | ~/.config/protonmail//prefs.json | // | c11 | ~/.cache/protonmail//c11 | ~/.cache/protonmail//cache/c11 | func MigrateFiles(configName string) error { - appDirs := appdir.New(filepath.Join(constants.VendorName, configName)) - locations := locations.New(appDirs, configName) + locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, configName)) + if err != nil { + return err + } - userCacheDir := appDirs.UserCache() + locations := locations.New(locationsProvider, configName) + userCacheDir := locationsProvider.UserCache() newSettingsDir, err := locations.ProvideSettingsPath() if err != nil { return err diff --git a/internal/locations/locations.go b/internal/locations/locations.go index 0e700771..74a026f6 100644 --- a/internal/locations/locations.go +++ b/internal/locations/locations.go @@ -40,15 +40,11 @@ type Locations struct { configName string } -type appDirsProvider interface { - UserConfig() string - UserCache() string -} - -func New(appDirs appDirsProvider, configName string) *Locations { +// New returns a new locations object. +func New(provider Provider, configName string) *Locations { return &Locations{ - userConfig: appDirs.UserConfig(), - userCache: appDirs.UserCache(), + userConfig: provider.UserConfig(), + userCache: provider.UserCache(), configName: configName, } } diff --git a/internal/locations/provider.go b/internal/locations/provider.go new file mode 100644 index 00000000..55b982c3 --- /dev/null +++ b/internal/locations/provider.go @@ -0,0 +1,59 @@ +// Copyright (c) 2021 Proton Technologies AG +// +// This file is part of ProtonMail Bridge. +// +// ProtonMail Bridge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ProtonMail Bridge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with ProtonMail Bridge. If not, see . + +package locations + +import ( + "os" + "path/filepath" +) + +// Provider provides standard locations. +type Provider interface { + UserConfig() string + UserCache() string +} + +// DefaultProvider is a locations provider using the system-default storage locations. +type DefaultProvider struct { + config, cache string +} + +func NewDefaultProvider(name string) (*DefaultProvider, error) { + config, err := os.UserConfigDir() + if err != nil { + return nil, err + } + + cache, err := os.UserCacheDir() + if err != nil { + return nil, err + } + + return &DefaultProvider{ + config: filepath.Join(config, name), + cache: filepath.Join(cache, name), + }, nil +} + +func (p *DefaultProvider) UserConfig() string { + return p.config +} + +func (p *DefaultProvider) UserCache() string { + return p.cache +} diff --git a/unreleased.md b/unreleased.md index 6aba92e1..1c1037ac 100644 --- a/unreleased.md +++ b/unreleased.md @@ -16,6 +16,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * GODT-851 Added support of UID EXPUNGE. ### Removed +* GODT-248 Remove dependency on go-appdir. ### Fixed * GODT-922 Fix panic during restarting the bridge.