mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
refactor: remove go-appdir dependency
This commit is contained in:
@ -23,7 +23,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/ProtonMail/go-appdir"
|
|
||||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/constants"
|
"github.com/ProtonMail/proton-bridge/internal/constants"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/crash"
|
"github.com/ProtonMail/proton-bridge/internal/crash"
|
||||||
@ -49,10 +48,12 @@ func main() { // nolint[funlen]
|
|||||||
crashHandler := crash.NewHandler(sentryReporter.Report)
|
crashHandler := crash.NewHandler(sentryReporter.Report)
|
||||||
defer crashHandler.HandlePanic()
|
defer crashHandler.HandlePanic()
|
||||||
|
|
||||||
locations := locations.New(
|
locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, ConfigName))
|
||||||
appdir.New(filepath.Join(constants.VendorName, ConfigName)),
|
if err != nil {
|
||||||
ConfigName,
|
logrus.WithError(err).Fatal("Failed to get locations provider")
|
||||||
)
|
}
|
||||||
|
|
||||||
|
locations := locations.New(locationsProvider, ConfigName)
|
||||||
|
|
||||||
logsPath, err := locations.ProvideLogsPath()
|
logsPath, err := locations.ProvideLogsPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
1
go.mod
1
go.mod
@ -14,7 +14,6 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1
|
github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1
|
||||||
github.com/Masterminds/semver/v3 v3.1.0
|
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-apple-mobileconfig v0.0.0-20160701194735-7ea9927a11f6
|
||||||
github.com/ProtonMail/go-autostart v0.0.0-20181114175602-c5272053443a
|
github.com/ProtonMail/go-autostart v0.0.0-20181114175602-c5272053443a
|
||||||
github.com/ProtonMail/go-imap-id v0.0.0-20190926060100-f94a56b9ecde
|
github.com/ProtonMail/go-imap-id v0.0.0-20190926060100-f94a56b9ecde
|
||||||
|
|||||||
2
go.sum
2
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/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 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
|
||||||
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
|
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 h1:YsSJ/mvZFYydQm/hRrt8R8UtgETixN2y3LK98f5LT60=
|
||||||
github.com/ProtonMail/go-apple-mobileconfig v0.0.0-20160701194735-7ea9927a11f6/go.mod h1:EtDfBMIDWmVe4viZCuBTEfe3OIIo0ghbpOaAZVO+hVg=
|
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=
|
github.com/ProtonMail/go-autostart v0.0.0-20181114175602-c5272053443a h1:fXK2KsfnkBV9Nh+9SKzHchYjuE9s0vI20JG1mbtEAcc=
|
||||||
|
|||||||
@ -35,7 +35,6 @@ import (
|
|||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
|
||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
"github.com/ProtonMail/go-appdir"
|
|
||||||
"github.com/ProtonMail/go-autostart"
|
"github.com/ProtonMail/go-autostart"
|
||||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/api"
|
"github.com/ProtonMail/proton-bridge/internal/api"
|
||||||
@ -99,10 +98,12 @@ func New( // nolint[funlen]
|
|||||||
)
|
)
|
||||||
defer crashHandler.HandlePanic()
|
defer crashHandler.HandlePanic()
|
||||||
|
|
||||||
locations := locations.New(
|
locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, configName))
|
||||||
appdir.New(filepath.Join(constants.VendorName, configName)),
|
if err != nil {
|
||||||
configName,
|
return nil, err
|
||||||
)
|
}
|
||||||
|
|
||||||
|
locations := locations.New(locationsProvider, configName)
|
||||||
if err := locations.Clean(); err != nil {
|
if err := locations.Clean(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/ProtonMail/go-appdir"
|
|
||||||
"github.com/ProtonMail/proton-bridge/internal/constants"
|
"github.com/ProtonMail/proton-bridge/internal/constants"
|
||||||
"github.com/ProtonMail/proton-bridge/internal/locations"
|
"github.com/ProtonMail/proton-bridge/internal/locations"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -35,10 +34,13 @@ import (
|
|||||||
// | prefs | ~/.cache/protonmail/<app>/c11/prefs.json | ~/.config/protonmail/<app>/prefs.json |
|
// | prefs | ~/.cache/protonmail/<app>/c11/prefs.json | ~/.config/protonmail/<app>/prefs.json |
|
||||||
// | c11 | ~/.cache/protonmail/<app>/c11 | ~/.cache/protonmail/<app>/cache/c11 |
|
// | c11 | ~/.cache/protonmail/<app>/c11 | ~/.cache/protonmail/<app>/cache/c11 |
|
||||||
func MigrateFiles(configName string) error {
|
func MigrateFiles(configName string) error {
|
||||||
appDirs := appdir.New(filepath.Join(constants.VendorName, configName))
|
locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, configName))
|
||||||
locations := locations.New(appDirs, configName)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
userCacheDir := appDirs.UserCache()
|
locations := locations.New(locationsProvider, configName)
|
||||||
|
userCacheDir := locationsProvider.UserCache()
|
||||||
newSettingsDir, err := locations.ProvideSettingsPath()
|
newSettingsDir, err := locations.ProvideSettingsPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -40,15 +40,11 @@ type Locations struct {
|
|||||||
configName string
|
configName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type appDirsProvider interface {
|
// New returns a new locations object.
|
||||||
UserConfig() string
|
func New(provider Provider, configName string) *Locations {
|
||||||
UserCache() string
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(appDirs appDirsProvider, configName string) *Locations {
|
|
||||||
return &Locations{
|
return &Locations{
|
||||||
userConfig: appDirs.UserConfig(),
|
userConfig: provider.UserConfig(),
|
||||||
userCache: appDirs.UserCache(),
|
userCache: provider.UserCache(),
|
||||||
configName: configName,
|
configName: configName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
internal/locations/provider.go
Normal file
59
internal/locations/provider.go
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@ -16,6 +16,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* GODT-851 Added support of UID EXPUNGE.
|
* GODT-851 Added support of UID EXPUNGE.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
* GODT-248 Remove dependency on go-appdir.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* GODT-922 Fix panic during restarting the bridge.
|
* GODT-922 Fix panic during restarting the bridge.
|
||||||
|
|||||||
Reference in New Issue
Block a user