mirror of
https://github.com/dokku/dokku.git
synced 2025-12-25 08:19:22 +01:00
fix: properly handle directory replacement
The previous version _also_ deleted the temp working dir, causing issues with subsequent directory access.
This commit is contained in:
20
plugins/builder/functions.go
Normal file
20
plugins/builder/functions.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func removeAllContents(basePath string) error {
|
||||
dir, err := ioutil.ReadDir(basePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, d := range dir {
|
||||
os.RemoveAll(path.Join([]string{basePath, d.Name()}...))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -3,10 +3,11 @@ module github.com/dokku/dokku/plugins/builder
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0
|
||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27
|
||||
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0
|
||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27
|
||||
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
||||
github.com/otiai10/copy v1.6.0
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
)
|
||||
|
||||
replace github.com/dokku/dokku/plugins/common => ../common
|
||||
|
||||
@@ -2,6 +2,12 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+Bu
|
||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
|
||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA=
|
||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
|
||||
github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ=
|
||||
github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
|
||||
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
|
||||
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
|
||||
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
|
||||
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
|
||||
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg=
|
||||
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/otiai10/copy"
|
||||
)
|
||||
|
||||
// TriggerBuilderDetect outputs a manually selected builder for the app
|
||||
@@ -42,19 +43,19 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
return fmt.Errorf("Unable to create temporary working directory: %v", err.Error())
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(tmpWorkDir); err != nil {
|
||||
if err := removeAllContents(tmpWorkDir); err != nil {
|
||||
return fmt.Errorf("Unable to clear out temporary working directory for rewrite: %v", err.Error())
|
||||
}
|
||||
|
||||
if err := os.Rename(newSourceWorkDir, tmpWorkDir); err != nil {
|
||||
if err := copy.Copy(newSourceWorkDir, tmpWorkDir); err != nil {
|
||||
return fmt.Errorf("Unable to move build-dir to temporary working directory: %v", err.Error())
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(sourceWorkDir); err != nil {
|
||||
if err := removeAllContents(sourceWorkDir); err != nil {
|
||||
return fmt.Errorf("Unable to clear out sourcecode working directory for rewrite: %v", err.Error())
|
||||
}
|
||||
|
||||
if err := os.Rename(tmpWorkDir, sourceWorkDir); err != nil {
|
||||
if err := copy.Copy(tmpWorkDir, sourceWorkDir); err != nil {
|
||||
return fmt.Errorf("Unable to move build-dir to sourcecode working directory: %v", err.Error())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user