跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

defaults_unix.go

58 行 · 1.4 KB历史下载
1//go:build !windows
2
3// SPDX-FileCopyrightText: Copyright The Lima Authors
4// SPDX-License-Identifier: Apache-2.0
5
6package limayaml
7
8import (
9 "errors"
10 "fmt"
11 "os"
12 "path/filepath"
13 "strings"
14 "time"
15
16 "github.com/sirupsen/logrus"
17)
18
19func hostTimeZone() string {
20 if tzBytes, err := os.ReadFile("/etc/timezone"); err == nil {
21 if tz := strings.TrimSpace(string(tzBytes)); tz != "" {
22 if _, err := time.LoadLocation(tz); err != nil {
23 logrus.Warnf("invalid timezone found in /etc/timezone: %v", err)
24 } else {
25 return tz
26 }
27 }
28 }
29
30 if zoneinfoFile, err := filepath.EvalSymlinks("/etc/localtime"); err == nil {
31 if tz, err := extractTZFromPath(zoneinfoFile); err != nil {
32 logrus.Warnf("failed to extract timezone from %s: %v", zoneinfoFile, err)
33 } else {
34 return tz
35 }
36 }
37
38 logrus.Warn("unable to determine host timezone, falling back to default value")
39 return ""
40}
41
42func extractTZFromPath(zoneinfoFile string) (string, error) {
43 if zoneinfoFile == "" {
44 return "", errors.New("invalid zoneinfo file path")
45 }
46
47 if _, err := os.Stat(zoneinfoFile); os.IsNotExist(err) {
48 return "", fmt.Errorf("zoneinfo file does not exist: %s", zoneinfoFile)
49 }
50
51 for dir := filepath.Dir(zoneinfoFile); dir != filepath.Dir(dir); dir = filepath.Dir(dir) {
52 if _, err := os.Stat(filepath.Join(dir, "Etc", "UTC")); err == nil {
53 return filepath.Rel(dir, zoneinfoFile)
54 }
55 }
56
57 return "", errors.New("timezone base directory not found")
58}