Files
multica/server/internal/daemon/execenv/codex_home_link_windows.go
LinYushen 526e336081 feat(execenv): add Windows fallback for symlink operations (#859)
On Windows, os.Symlink requires Developer Mode or admin privileges.
Extract symlink creation into platform-specific files: on non-Windows,
behavior is unchanged (os.Symlink). On Windows, try os.Symlink first,
then fall back to directory junctions (mklink /J) for dirs and file
copy for files.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:23:41 +08:00

33 lines
827 B
Go

//go:build windows
package execenv
import (
"fmt"
"os"
"os/exec"
)
// createDirLink tries os.Symlink first (requires Developer Mode or admin on
// Windows). If that fails, it falls back to a directory junction (mklink /J)
// which works without elevated privileges.
func createDirLink(src, dst string) error {
if err := os.Symlink(src, dst); err == nil {
return nil
}
out, err := exec.Command("cmd", "/c", "mklink", "/J", dst, src).CombinedOutput()
if err != nil {
return fmt.Errorf("mklink /J %s %s: %s: %w", dst, src, out, err)
}
return nil
}
// createFileLink tries os.Symlink first. If that fails, it falls back to
// copying the file so the content is still available.
func createFileLink(src, dst string) error {
if err := os.Symlink(src, dst); err == nil {
return nil
}
return copyFile(src, dst)
}