Skip to content

cli: streamline autostart ux #2251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 13, 2022
Prev Previous commit
Next Next commit
more fixes
  • Loading branch information
johnstcn committed Jun 10, 2022
commit 68187d88c0a717b0e32f75e5908b00535d986c2e
13 changes: 11 additions & 2 deletions coderd/util/tz/tz_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"
"time"

"golang.org/x/xerrors"
)

const etcLocaltime = "/etc/localtime"
Expand Down Expand Up @@ -36,10 +38,17 @@ func TimezoneIANA() (*time.Location, error) {
return nil, xerrors.Errorf("read location of %s: %w", etcLocaltime, err)
}

stripped := strings.Replace(lp, etcLocaltime, "", -1)
// On Darwin, /var/db/timezone/zoneinfo is also a symlink
realZoneInfoPath, err := filepath.EvalSymlinks(zoneInfoPath)
if err != nil {
return nil, xerrors.Errorf("read location of %s: %w", zoneInfoPath, err)
}

stripped := strings.Replace(lp, realZoneInfoPath, "", -1)
stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
loc, err := time.LoadLocation(stripped)
if err != nil {
return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", stripped, lp, err)
}
return loc
return loc, nil
}
3 changes: 2 additions & 1 deletion coderd/util/tz/tz_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const etcLocaltime = "/etc/localtime"
const zoneInfoPath = "/usr/share/zoneinfo/"
const zoneInfoPath = "/usr/share/zoneinfo"

// TimezoneIANA attempts to determine the local timezone in IANA format.
// If the TZ environment variable is set, this is used.
Expand Down Expand Up @@ -40,6 +40,7 @@ func TimezoneIANA() (*time.Location, error) {
}

stripped := strings.Replace(lp, zoneInfoPath, "", -1)
stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
loc, err := time.LoadLocation(stripped)
if err != nil {
return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", stripped, lp, err)
Expand Down
2 changes: 1 addition & 1 deletion coderd/util/tz/tz_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TimezoneIANA() (*time.Location, error) {
}

// https://superuser.com/a/1584968
cmd := exec.Command("powershell.exe", "-nologo", "-noprofile")
cmd := exec.Command("powershell.exe", "-NoLogo", "-NoProfile", "-NonInteractive")
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, xerrors.Errorf("run powershell: %w", err)
Expand Down