Skip to content

fix: do not crash when a symlink we try to create is already present … #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion local/php/executor_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ package php

import (
"os"
"path/filepath"
"syscall"

"github.com/pkg/errors"
)

func shouldSignalBeIgnored(sig os.Signal) bool {
Expand All @@ -34,5 +37,13 @@ func shouldSignalBeIgnored(sig os.Signal) bool {
}

func symlink(oldname, newname string) error {
return os.Symlink(oldname, newname)
err := errors.WithStack(os.Symlink(oldname, newname))

if os.IsExist(errors.Cause(err)) {
if target, _ := filepath.EvalSymlinks(newname); target == oldname {
return nil
}
}

return err
}
8 changes: 5 additions & 3 deletions local/php/executor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package php
import (
"io"
"os"

"github.com/pkg/errors"
)

func shouldSignalBeIgnored(sig os.Signal) bool {
Expand All @@ -31,14 +33,14 @@ func shouldSignalBeIgnored(sig os.Signal) bool {
func symlink(oldname, newname string) error {
source, err := os.Open(oldname)
if err != nil {
return err
return errors.WithStack(err)
}
defer source.Close()
destination, err := os.Create(newname)
if err != nil {
return err
return errors.WithStack(err)
}
defer destination.Close()
_, err = io.Copy(destination, source)
return err
return errors.WithStack(err)
}