Files
gluetun/internal/updater/updater.go
T
Quentin McGaw d9cc7dcffb refactor(storage): new storage file structure
- new directory structure containing manifest.json and one json file per provider, by default.
- the manifest.json file can specify a filepath for each vpn provider
- each vpn provider json data file can contain the `"preferred": true` field to enforce it is used even if outdated, unless there is a version mismatch
- `STORAGE_SERVERS_DIRECTORY_PATH` replaces `STORAGE_FILEPATH` (which is now a migration source only). It sets the directory where server manifest and per-provider JSON files are stored (default: `/gluetun/servers/`).
- First-run migration: On startup, gluetun checks for the old /gluetun/servers.json file; if found and no new manifest exists, it automatically migrates all data to /gluetun/servers/ directory structure
- Silent fallback: If legacy file isn't found, uses the new directory path normally
- Legacy cleanup: After successful migration, attempts to remove the old fat JSON file (logs warning only if removal fails, e.g., read-only bind mounts)
2026-05-11 04:53:04 +00:00

73 lines
1.7 KiB
Go

package updater
import (
"context"
"errors"
"net/http"
"time"
"github.com/qdm12/gluetun-servers/pkg/updaters/common"
"github.com/qdm12/gluetun-servers/pkg/updaters/unzip"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
type Updater struct {
providers Providers
// state
storage Storage
// Functions for tests
logger Logger
timeNow func() time.Time
client *http.Client
unzipper Unzipper
}
func New(httpClient *http.Client, storage Storage,
providers Providers, logger Logger,
) *Updater {
unzipper := unzip.New(httpClient)
return &Updater{
providers: providers,
storage: storage,
logger: logger,
timeNow: time.Now,
client: httpClient,
unzipper: unzipper,
}
}
func (u *Updater) UpdateServers(ctx context.Context, providers []string,
minRatio float64,
) (err error) {
caser := cases.Title(language.English)
for _, providerName := range providers {
u.logger.Info("updating " + caser.String(providerName) + " servers...")
fetcher := u.providers.Get(providerName)
// TODO support servers offering only TCP or only UDP
// for NordVPN and PureVPN
err := u.updateProvider(ctx, fetcher, minRatio)
switch {
case err == nil:
continue
case errors.Is(err, common.ErrCredentialsMissing):
u.logger.Warn(err.Error() + " - skipping update for " + providerName)
continue
case len(providers) == 1:
// return the only error for the single provider.
return err
case ctx.Err() != nil:
// stop updating other providers if context is done
return ctx.Err()
default: // error encountered updating one of multiple providers
// Log the error and continue updating the next provider.
u.logger.Error(err.Error())
}
}
return nil
}