mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:20:43 +00:00
fix: keep docs i18n codex home out of tmp
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -179,7 +180,11 @@ func runCodexExecPrompt(ctx context.Context, req codexPromptRequest) (string, er
|
||||
_ = outputFile.Close()
|
||||
defer os.Remove(outputPath)
|
||||
|
||||
codexHome, err := os.MkdirTemp("", "openclaw-docs-i18n-codex-home-*")
|
||||
codexHomeBase, err := isolatedCodexHomeBase()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
codexHome, err := os.MkdirTemp(codexHomeBase, "codex-home-*")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -217,6 +222,22 @@ func runCodexExecPrompt(ctx context.Context, req codexPromptRequest) (string, er
|
||||
return translated, nil
|
||||
}
|
||||
|
||||
func isolatedCodexHomeBase() (string, error) {
|
||||
cacheDir, err := os.UserCacheDir()
|
||||
if err != nil || strings.TrimSpace(cacheDir) == "" {
|
||||
homeDir, homeErr := os.UserHomeDir()
|
||||
if homeErr != nil {
|
||||
return "", err
|
||||
}
|
||||
cacheDir = filepath.Join(homeDir, ".cache")
|
||||
}
|
||||
base := filepath.Join(cacheDir, "openclaw-docs-i18n")
|
||||
if err := os.MkdirAll(base, 0o700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base, nil
|
||||
}
|
||||
|
||||
func docsCodexExecutable() string {
|
||||
if executable := strings.TrimSpace(os.Getenv(envDocsI18nCodexExecutable)); executable != "" {
|
||||
return executable
|
||||
|
||||
@@ -153,6 +153,12 @@ if [ -z "${CODEX_HOME:-}" ]; then
|
||||
echo "missing CODEX_HOME" >&2
|
||||
exit 1
|
||||
fi
|
||||
case "$CODEX_HOME" in
|
||||
/tmp/*)
|
||||
echo "CODEX_HOME must not be under /tmp" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
printf 'translated from codex\n' > "$out"
|
||||
`), 0o755); err != nil {
|
||||
t.Fatalf("write fake codex: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user