Skip to content

Commit e0c4727

Browse files
Touch binary and the .lastRun to avoid auto deletion in /var/tmp
1 parent 00bc87f commit e0c4727

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

gorun.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,14 @@ func (s *Script) waitForActiveBuilds() bool {
561561
return false
562562
}
563563

564-
func touchFile(file string) (err error) {
564+
func touchFile(file string, onlyIfExists bool) (err error) {
565565
_, err = os.Stat(file)
566566
if os.IsNotExist(err) {
567-
var f *os.File
568-
f, err = os.Create(file)
569-
defer f.Close()
567+
if !onlyIfExists {
568+
var f *os.File
569+
f, err = os.Create(file)
570+
defer f.Close()
571+
}
570572
} else {
571573
currentTime := time.Now().Local()
572574
err = os.Chtimes(file, currentTime, currentTime)
@@ -577,7 +579,8 @@ func touchFile(file string) (err error) {
577579
// run runs the binary and marks when it was last run (by touching a file alongside the binary)
578580
func (s *Script) run() (err error) {
579581
if s.cleanSecs >= 0 {
580-
_ = touchFile(s.binaryLastRun)
582+
_ = touchFile(s.binaryLastRun, false)
583+
_ = touchFile(s.binary, true)
581584
}
582585
err = syscall.Exec(s.binary, s.args, os.Environ())
583586
return

0 commit comments

Comments
 (0)