Files
Memoh/internal/containerd/timezone.go
T
晨苒 d50eeea114 reactor(cli): move memoh cli to tui
1. Split the oversized `cmd/agent` entrypoint into a multi-file package and update dev/build scripts to use the package path instead of compiling `main.go` directly.
2. Add a new `memoh` terminal UI for local bot chat, with Bubble Tea
2026-04-14 06:22:00 +08:00

38 lines
1021 B
Go

package containerd
import (
"os"
"path/filepath"
"strings"
)
// TimezoneSpec returns environment variables that propagate the host timezone
// into the container without relying on file bind mounts like /etc/localtime.
// File mounts can fail for workspace containers when the target path is absent
// in the unpacked rootfs, while TZ is sufficient for Go, Node, and most tools.
func TimezoneSpec() ([]MountSpec, []string) {
var env []string
if tz := detectTimezone(); tz != "" {
env = append(env, "TZ="+tz)
}
return nil, env
}
func detectTimezone() string {
if tz := strings.TrimSpace(os.Getenv("TZ")); tz != "" {
return tz
}
if data, err := os.ReadFile("/etc/timezone"); err == nil {
if tz := strings.TrimSpace(string(data)); tz != "" {
return tz
}
}
if target, err := filepath.EvalSymlinks("/etc/localtime"); err == nil {
const zoneinfoPrefix = "/usr/share/zoneinfo/"
if strings.HasPrefix(target, zoneinfoPrefix) {
return strings.TrimPrefix(target, zoneinfoPrefix)
}
}
return ""
}