cmd/tailscaled: actually derive statedir from statepath

The documentation for `--statedir` says that if unspecified, it will be derived
from `--state` if possible. It was not. In addition, if `--state` was specified,
`--statedir` was not even defaulted to its usual default, so remained empty.

Now, if only `--state` is specified, `--statedir` is derived from it.

Updates #14025

Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:
Percy Wegmann 2025-09-04 06:36:52 -05:00
parent d8ac539bf9
commit 9fe21bb382
No known key found for this signature in database
GPG Key ID: 29D8CDEB4C13D48B

View File

@ -255,9 +255,9 @@ func main() {
log.Fatalf("--bird-socket is not supported on %s", runtime.GOOS)
}
// Only apply a default statepath when neither have been provided, so that a
// user may specify only --statedir if they wish.
if args.statepath == "" && args.statedir == "" {
// Only apply a default statepath when neither have been provided, so that a
// user may specify only --statedir if they wish.
if paths.MakeAutomaticStateDir() {
d := paths.DefaultTailscaledStateDir()
if d != "" {
@ -269,6 +269,9 @@ func main() {
} else {
args.statepath = paths.DefaultTailscaledStateFile()
}
} else if args.statedir == "" && args.statepath != "" {
// When only a statepath is specified, derive statedir from statepath.
args.statedir = filepath.Dir(args.statepath)
}
if args.encryptState {