Skip to content

Commit ed9191e

Browse files
committed
fix: do not crash when a symlink we try to create is already present and with the designated target, fix #603
1 parent 5f17f1d commit ed9191e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

local/php/executor_posix.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ package php
2424

2525
import (
2626
"os"
27+
"path/filepath"
2728
"syscall"
29+
30+
"github.com/pkg/errors"
2831
)
2932

3033
func shouldSignalBeIgnored(sig os.Signal) bool {
@@ -34,5 +37,13 @@ func shouldSignalBeIgnored(sig os.Signal) bool {
3437
}
3538

3639
func symlink(oldname, newname string) error {
37-
return os.Symlink(oldname, newname)
40+
err := errors.WithStack(os.Symlink(oldname, newname))
41+
42+
if os.IsExist(errors.Cause(err)) {
43+
if target, _ := filepath.EvalSymlinks(newname); target == oldname {
44+
return nil
45+
}
46+
}
47+
48+
return err
3849
}

local/php/executor_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ package php
2222
import (
2323
"io"
2424
"os"
25+
26+
"github.com/pkg/errors"
2527
)
2628

2729
func shouldSignalBeIgnored(sig os.Signal) bool {
@@ -31,14 +33,14 @@ func shouldSignalBeIgnored(sig os.Signal) bool {
3133
func symlink(oldname, newname string) error {
3234
source, err := os.Open(oldname)
3335
if err != nil {
34-
return err
36+
return errors.WithStack(err)
3537
}
3638
defer source.Close()
3739
destination, err := os.Create(newname)
3840
if err != nil {
39-
return err
41+
return errors.WithStack(err)
4042
}
4143
defer destination.Close()
4244
_, err = io.Copy(destination, source)
43-
return err
45+
return errors.WithStack(err)
4446
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy