permitir no borrar archivos temporales
This commit is contained in:
parent
644e73f037
commit
19029262f8
4 changed files with 16 additions and 4 deletions
2
cli.go
2
cli.go
|
@ -11,7 +11,7 @@ import (
|
|||
func main() {
|
||||
config, err := readConfig()
|
||||
must(err)
|
||||
must(runner.Run(config, "rootfs/", "cache/", ".", nil))
|
||||
must(runner.Run(config, "rootfs/", "cache/", ".", nil, false))
|
||||
}
|
||||
|
||||
func must(err error, where ...string) {
|
||||
|
|
|
@ -47,6 +47,7 @@ type config struct {
|
|||
giteaUsername string
|
||||
giteaPassword string
|
||||
publicUrl string
|
||||
doNotDeleteTmp bool
|
||||
}
|
||||
|
||||
func parseConfig() (c config) {
|
||||
|
@ -75,5 +76,7 @@ func parseConfig() (c config) {
|
|||
c.publicUrl = "http://localhost:8080"
|
||||
}
|
||||
|
||||
c.doNotDeleteTmp = os.Getenv("DO_NOT_DELETE_TMP") == "true"
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ func (h webhook) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
err = runner.Run(*runnerConfig, rootfs, cache, src, run)
|
||||
err = runner.Run(*runnerConfig, rootfs, cache, src, run, h.config.doNotDeleteTmp)
|
||||
state := "success"
|
||||
if err != nil {
|
||||
log.Println("runner.Run", err)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
//go:embed alpine/keys
|
||||
var alpineKeys embed.FS
|
||||
|
||||
func Run(config Config, rootfs string, cache string, src string, w io.Writer) (err error) {
|
||||
func Run(config Config, rootfs string, cache string, src string, w io.Writer, dontDeleteTemp bool) (err error) {
|
||||
if err = os.RemoveAll(rootfs); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
defer removeTemp(tmp, dontDeleteTemp)
|
||||
log.Println("/work = " + tmp)
|
||||
|
||||
params := append(
|
||||
|
@ -130,3 +130,12 @@ type Config struct {
|
|||
Command string
|
||||
Cache []string
|
||||
}
|
||||
|
||||
func removeTemp(name string, dontRemoveTemp bool) {
|
||||
if !dontRemoveTemp {
|
||||
err := os.RemoveAll(name)
|
||||
if err != nil {
|
||||
log.Printf("No pude borrar %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue