Files
gluetun/internal/publicip/update.go
Quentin McGaw 03deb9aed0 feat(publicip): PUBLICIP_ENABLED replaces PUBLICIP_PERIOD
- No point periodically fetch the public IP address. Could not find anything mentioning why this was added.
- Simplification of the publicip loop code
- `PUBLICIP_ENABLED` (on, off) can be set to enable or not public ip data fetching on VPN connection
- `PUBLICIP_PERIOD=0` still works to indicate to disable public ip fetching
- `PUBLICIP_PERIOD` != 0 means to enable public ip fetching
- Warnings logged when using `PUBLICIP_PERIOD`
2024-10-08 11:30:31 +00:00

45 lines
1.1 KiB
Go

package publicip
import (
"fmt"
"os"
"github.com/qdm12/gluetun/internal/configuration/settings"
)
func (l *Loop) update(partialUpdate settings.PublicIP) (err error) {
// No need to lock the mutex since it can only be written
// in the code below in this goroutine.
updatedSettings, err := l.settings.UpdateWith(partialUpdate)
if err != nil {
return err
}
if *l.settings.IPFilepath != *updatedSettings.IPFilepath {
switch {
case *l.settings.IPFilepath == "":
err = persistPublicIP(*updatedSettings.IPFilepath,
l.ipData.IP.String(), l.puid, l.pgid)
if err != nil {
return fmt.Errorf("persisting ip data: %w", err)
}
case *updatedSettings.IPFilepath == "":
err = os.Remove(*l.settings.IPFilepath)
if err != nil {
return fmt.Errorf("removing ip data file path: %w", err)
}
default:
err = os.Rename(*l.settings.IPFilepath, *updatedSettings.IPFilepath)
if err != nil {
return fmt.Errorf("renaming ip data file path: %w", err)
}
}
}
l.settingsMutex.Lock()
l.settings = updatedSettings
l.settingsMutex.Unlock()
return nil
}