Skip to content

Commit 300c0ef

Browse files
committed
cmd/buildlet: clamp modtime to be no greater than current time
Updates golang/go#19062 Change-Id: I12faf2941083d44466e6ff8a053c832631276ffe Reviewed-on: https://go-review.googlesource.com/37381 Reviewed-by: Lynn Boger <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 88f4d73 commit 300c0ef

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmd/buildlet/buildlet.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ func untar(r io.Reader, dir string) (err error) {
640640
return badRequest("requires gzip-compressed body: " + err.Error())
641641
}
642642
tr := tar.NewReader(zr)
643+
loggedChtimesError := false
643644
for {
644645
f, err := tr.Next()
645646
if err == io.EOF {
@@ -684,14 +685,23 @@ func untar(r io.Reader, dir string) (err error) {
684685
if n != f.Size {
685686
return fmt.Errorf("only wrote %d bytes to %s; expected %d", n, abs, f.Size)
686687
}
687-
if !f.ModTime.IsZero() {
688-
if err := os.Chtimes(abs, f.ModTime, f.ModTime); err != nil {
688+
modTime := f.ModTime
689+
if modTime.After(t0) {
690+
// Clamp modtimes at system time. See
691+
// golang.org/issue/19062 when clock on
692+
// buildlet was behind the gitmirror server
693+
// doing the git-archive.
694+
modTime = t0
695+
}
696+
if !modTime.IsZero() {
697+
if err := os.Chtimes(abs, modTime, modTime); err != nil && !loggedChtimesError {
689698
// benign error. Gerrit doesn't even set the
690699
// modtime in these, and we don't end up relying
691700
// on it anywhere (the gomote push command relies
692701
// on digests only), so this is a little pointless
693702
// for now.
694-
log.Printf("error changing modtime: %v", err)
703+
log.Printf("error changing modtime: %v (further Chtimes errors suppressed)", err)
704+
loggedChtimesError = true // once is enough
695705
}
696706
}
697707
nFiles++

0 commit comments

Comments
 (0)