Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd820fed

Browse files
committed
fix: cleanup additional temporary directories
1 parenta2f79df commitd820fed

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

‎commands/local_server_start.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ var localServerStartCmd = &console.Command{
421421
ifp.PHPServer!=nil {
422422
<-p.PHPServer.StoppedChan
423423
}
424+
pidFile.CleanupDirectories()
424425
ui.Success("Stopped all processes successfully")
425426
}
426427
returnnil

‎local/php/fpm.go‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,5 @@ env['LC_ALL'] = C
114114
}
115115

116116
func (p*Server)fpmConfigFile()string {
117-
path:=filepath.Join(p.homeDir,fmt.Sprintf("php/%s/fpm-%s.ini",name(p.projectDir),p.Version.Version))
118-
if_,err:=os.Stat(filepath.Dir(path));os.IsNotExist(err) {
119-
_=os.MkdirAll(filepath.Dir(path),0755)
120-
}
121-
returnpath
117+
returnfilepath.Join(p.tempDir,fmt.Sprintf("fpm-%s.ini",p.Version.Version))
122118
}

‎local/php/php_builtin_server.go‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package php
2121

2222
import (
2323
"fmt"
24-
"os"
2524
"path/filepath"
2625
)
2726

@@ -61,9 +60,5 @@ require $script;
6160
`)
6261

6362
func (p*Server)phpRouterFile()string {
64-
path:=filepath.Join(p.homeDir,fmt.Sprintf("php/%s-router.php",name(p.projectDir)))
65-
if_,err:=os.Stat(filepath.Dir(path));os.IsNotExist(err) {
66-
_=os.MkdirAll(filepath.Dir(path),0755)
67-
}
68-
returnpath
63+
returnfilepath.Join(p.tempDir,fmt.Sprintf("%s-router.php",p.Version.Version))
6964
}

‎local/php/php_server.go‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ type Server struct {
5050
logger zerolog.Logger
5151
StoppedChanchanbool
5252
appVersionstring
53-
homeDirstring
5453
projectDirstring
5554
documentRootstring
5655
passthrustring
5756
addrstring
5857
proxy*httputil.ReverseProxy
58+
59+
tempDirstring
5960
}
6061

6162
varaddslashes=strings.NewReplacer("\\","\\\\","'","\\'")
@@ -76,7 +77,6 @@ func NewServer(homeDir, projectDir, documentRoot, passthru, appVersion string, l
7677
Version:version,
7778
logger:logger.With().Str("source","PHP").Str("php",version.Version).Str("path",version.ServerPath()).Logger(),
7879
appVersion:appVersion,
79-
homeDir:homeDir,
8080
projectDir:projectDir,
8181
documentRoot:documentRoot,
8282
passthru:passthru,
@@ -86,7 +86,13 @@ func NewServer(homeDir, projectDir, documentRoot, passthru, appVersion string, l
8686

8787
// Start starts a PHP server
8888
func (p*Server)Start(ctx context.Context,pidFile*pid.PidFile) (*pid.PidFile,func()error,error) {
89-
varpathsToRemove []string
89+
p.tempDir=pidFile.TempDirectory()
90+
if_,err:=os.Stat(p.tempDir);os.IsNotExist(err) {
91+
iferr=os.MkdirAll(p.tempDir,0755);err!=nil {
92+
returnnil,nil,err
93+
}
94+
}
95+
9096
port,err:=process.FindAvailablePort()
9197
iferr!=nil {
9298
p.logger.Debug().Err(err).Msg("unable to find an available port")
@@ -125,7 +131,6 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
125131
returnnil,nil,errors.WithStack(err)
126132
}
127133
p.proxy.Transport=&cgiTransport{}
128-
pathsToRemove=append(pathsToRemove,fpmConfigFile)
129134
binName="php-fpm"
130135
workerName="PHP-FPM"
131136
args= []string{p.Version.ServerPath(),"--nodaemonize","--fpm-config",fpmConfigFile}
@@ -151,7 +156,6 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
151156
iferr:=os.WriteFile(routerPath,phprouter,0644);err!=nil {
152157
returnnil,nil,errors.WithStack(err)
153158
}
154-
pathsToRemove=append(pathsToRemove,routerPath)
155159
binName="php"
156160
workerName="PHP"
157161
args= []string{p.Version.ServerPath(),"-S","127.0.0.1:"+strconv.Itoa(port),"-d","variables_order=EGPCS",routerPath}
@@ -194,9 +198,6 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
194198

195199
returnphpPidFile,func()error {
196200
deferfunc() {
197-
for_,path:=rangepathsToRemove {
198-
os.RemoveAll(path)
199-
}
200201
e.CleanupTemporaryDirectories()
201202
p.StoppedChan<-true
202203
}()

‎local/pid/pidfile.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ func (p *PidFile) WorkerPidDir() string {
232232
returnfilepath.Join(util.GetHomeDir(),"var",name(p.Dir))
233233
}
234234

235+
func (p*PidFile)TempDirectory()string {
236+
returnfilepath.Join(util.GetHomeDir(),"php",name(p.Dir))
237+
}
238+
239+
func (p*PidFile)CleanupDirectories() {
240+
os.RemoveAll(p.TempDirectory())
241+
// We don't want to force removal of log and pid files, we only want to
242+
// clean up empty directories. To do so we use `os.Remove` instead of
243+
// `os.RemoveAll`
244+
os.Remove(p.WorkerLogDir())
245+
os.Remove(p.WorkerPidDir())
246+
}
247+
235248
func (p*PidFile)LogReader() (io.ReadCloser,error) {
236249
logFile:=p.LogFile()
237250
iferr:=os.MkdirAll(filepath.Dir(logFile),0755);err!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp