Skip to content

Commit 35a12c3

Browse files
tas50claude
andcommitted
🐛 Fix timezone extraction for posix/right symlinks, add RunCommand guard for Windows
Strip posix/ and right/ prefixes from zoneinfo symlink targets so /etc/localtime → .../zoneinfo/posix/Asia/Tokyo correctly returns "Asia/Tokyo" instead of the invalid "posix/Asia/Tokyo". Add Capability_RunCommand check to Windows date provider, matching the Unix implementation, so static targets don't error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 39f95f0 commit 35a12c3

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

providers/os/resources/date/unix.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,17 @@ func extractTZFromPath(path string) string {
134134
const marker = "zoneinfo/"
135135
if idx := strings.LastIndex(path, marker); idx >= 0 {
136136
tz := path[idx+len(marker):]
137-
if tz != "" && tz != "localtime" {
138-
return tz
137+
if tz == "" || tz == "localtime" {
138+
return ""
139139
}
140+
// Strip posix/ and right/ prefixes — these are alternate
141+
// representations of the same zones, not valid IANA names.
142+
tz = strings.TrimPrefix(tz, "posix/")
143+
tz = strings.TrimPrefix(tz, "right/")
144+
if tz == "" {
145+
return ""
146+
}
147+
return tz
140148
}
141149
return ""
142150
}

providers/os/resources/date/unix_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ func TestExtractTZFromPath(t *testing.T) {
104104
want: "Europe/London",
105105
},
106106
{
107-
name: "posix subdirectory path returns full relative",
107+
name: "posix subdirectory path stripped",
108108
path: "/usr/share/zoneinfo/posix/Asia/Tokyo",
109-
want: "posix/Asia/Tokyo",
109+
want: "Asia/Tokyo",
110+
},
111+
{
112+
name: "right subdirectory path stripped",
113+
path: "/usr/share/zoneinfo/right/Europe/Berlin",
114+
want: "Europe/Berlin",
110115
},
111116
{
112117
name: "no zoneinfo marker",

providers/os/resources/date/windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func (w *Windows) Name() string {
3030
}
3131

3232
func (w *Windows) Get() (*Result, error) {
33+
if !w.conn.Capabilities().Has(shared.Capability_RunCommand) {
34+
return &Result{Timezone: "UTC"}, nil
35+
}
36+
3337
cmd, err := w.conn.RunCommand(powershell.Wrap(windowsDateCmd))
3438
if err != nil {
3539
return nil, fmt.Errorf("failed to get system date: %w", err)

0 commit comments

Comments
 (0)