permitir no borrar archivos temporales

This commit is contained in:
Cat /dev/Nulo 2023-01-23 11:50:06 -03:00
parent 644e73f037
commit 19029262f8
4 changed files with 16 additions and 4 deletions

2
cli.go
View file

@ -11,7 +11,7 @@ import (
func main() { func main() {
config, err := readConfig() config, err := readConfig()
must(err) must(err)
must(runner.Run(config, "rootfs/", "cache/", ".", nil)) must(runner.Run(config, "rootfs/", "cache/", ".", nil, false))
} }
func must(err error, where ...string) { func must(err error, where ...string) {

View file

@ -47,6 +47,7 @@ type config struct {
giteaUsername string giteaUsername string
giteaPassword string giteaPassword string
publicUrl string publicUrl string
doNotDeleteTmp bool
} }
func parseConfig() (c config) { func parseConfig() (c config) {
@ -75,5 +76,7 @@ func parseConfig() (c config) {
c.publicUrl = "http://localhost:8080" c.publicUrl = "http://localhost:8080"
} }
c.doNotDeleteTmp = os.Getenv("DO_NOT_DELETE_TMP") == "true"
return return
} }

View file

@ -213,7 +213,7 @@ func (h webhook) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
err = runner.Run(*runnerConfig, rootfs, cache, src, run) err = runner.Run(*runnerConfig, rootfs, cache, src, run, h.config.doNotDeleteTmp)
state := "success" state := "success"
if err != nil { if err != nil {
log.Println("runner.Run", err) log.Println("runner.Run", err)

View file

@ -14,7 +14,7 @@ import (
//go:embed alpine/keys //go:embed alpine/keys
var alpineKeys embed.FS 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 { if err = os.RemoveAll(rootfs); err != nil {
return return
} }
@ -78,7 +78,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
if err != nil { if err != nil {
return return
} }
defer os.RemoveAll(tmp) defer removeTemp(tmp, dontDeleteTemp)
log.Println("/work = " + tmp) log.Println("/work = " + tmp)
params := append( params := append(
@ -130,3 +130,12 @@ type Config struct {
Command string Command string
Cache []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)
}
}
}