Skip to content

Commit a2f79df

Browse files
committed
fix: cleanup $HOME/.symfony5/tmp temporary directories
1 parent f205bca commit a2f79df

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

commands/local_server_start.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ var localServerStartCmd = &console.Command{
417417
return err
418418
}
419419
terminal.Eprintln("")
420+
// wait for the PHP Server to be done cleaning up
421+
if p.PHPServer != nil {
422+
<-p.PHPServer.StoppedChan
423+
}
420424
ui.Success("Stopped all processes successfully")
421425
}
422426
return nil

local/php/executor.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ func (e *Executor) DetectScriptDir() (string, error) {
163163
return e.scriptDir, nil
164164
}
165165

166-
// Config determines the right version of PHP depending on the configuration (+ its configuration)
166+
// Config determines the right version of PHP depending on the configuration
167+
// (+ its configuration). It also creates some symlinks to ease the integration
168+
// with underlying tools that could try to run PHP. This is the responsability
169+
// of the caller to clean those temporary files. One can call
170+
// CleanupTemporaryDirectories to do so.
167171
func (e *Executor) Config(loadDotEnv bool) error {
168172
// reset environment
169173
e.environ = make([]string, 0)
@@ -220,8 +224,10 @@ func (e *Executor) Config(loadDotEnv bool) error {
220224
// prepending the PHP directory in the PATH does not work well if the PHP binary is not named "php" (like php7.3 for instance)
221225
// in that case, we create a temp directory with a symlink
222226
// we also link php-config for pecl to pick up the right one (it is always looks for something called php-config)
223-
phpDir := filepath.Join(cliDir, "tmp", xid.New().String(), "bin")
224-
e.tempDir = phpDir
227+
if e.tempDir == "" {
228+
e.tempDir = filepath.Join(cliDir, "tmp", xid.New().String())
229+
}
230+
phpDir := filepath.Join(e.tempDir, "bin")
225231
if err := os.MkdirAll(phpDir, 0755); err != nil {
226232
return err
227233
}
@@ -284,6 +290,15 @@ func (e *Executor) Config(loadDotEnv bool) error {
284290
return err
285291
}
286292

293+
func (e *Executor) CleanupTemporaryDirectories() {
294+
if e.iniDir != "" {
295+
os.RemoveAll(e.iniDir)
296+
}
297+
if e.tempDir != "" {
298+
os.RemoveAll(e.tempDir)
299+
}
300+
}
301+
287302
// Find composer depending on the configuration
288303
func (e *Executor) findComposer(extraBin string) (string, error) {
289304
if scriptDir, err := e.DetectScriptDir(); err == nil {
@@ -312,14 +327,7 @@ func (e *Executor) Execute(loadDotEnv bool) int {
312327
fmt.Fprintln(os.Stderr, err)
313328
return 1
314329
}
315-
defer func() {
316-
if e.iniDir != "" {
317-
os.RemoveAll(e.iniDir)
318-
}
319-
if e.tempDir != "" {
320-
os.RemoveAll(e.tempDir)
321-
}
322-
}()
330+
defer e.CleanupTemporaryDirectories()
323331
cmd := execCommand(e.Args[0], e.Args[1:]...)
324332
environ := append(os.Environ(), e.environ...)
325333
gpathname := "PATH"

local/php/php_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
type Server struct {
4949
Version *phpstore.Version
5050
logger zerolog.Logger
51+
StoppedChan chan bool
5152
appVersion string
5253
homeDir string
5354
projectDir string
@@ -79,6 +80,7 @@ func NewServer(homeDir, projectDir, documentRoot, passthru, appVersion string, l
7980
projectDir: projectDir,
8081
documentRoot: documentRoot,
8182
passthru: passthru,
83+
StoppedChan: make(chan bool, 1),
8284
}, nil
8385
}
8486

@@ -195,6 +197,8 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
195197
for _, path := range pathsToRemove {
196198
os.RemoveAll(path)
197199
}
200+
e.CleanupTemporaryDirectories()
201+
p.StoppedChan <- true
198202
}()
199203

200204
return errors.Wrap(errors.WithStack(runner.Run()), "PHP server exited unexpectedly")

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