fix: keep docs i18n codex home out of tmp

This commit is contained in:
Peter Steinberger
2026-04-28 05:05:01 +01:00
parent 1e3ce10e27
commit 97f3e6d3c2
2 changed files with 28 additions and 1 deletions

View File

@@ -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

View File

@@ -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)