@@ -555,15 +555,25 @@ func getJobNameForLogFilename(name string) string {
555555 return sanitizedJobName
556556}
557557
558+ // A job run log file is a top-level .txt file whose name starts with an ordinal
559+ // number; e.g., "0_jobname.txt".
558560func jobLogFilenameRegexp (job shared.Job ) * regexp.Regexp {
559561 sanitizedJobName := getJobNameForLogFilename (job .Name )
560- re := fmt .Sprintf (`^-?\d+_%s\.txt` , regexp .QuoteMeta (sanitizedJobName ))
562+ re := fmt .Sprintf (`^\d+_%s\.txt$` , regexp .QuoteMeta (sanitizedJobName ))
563+ return regexp .MustCompile (re )
564+ }
565+
566+ // A legacy job run log file is a top-level .txt file whose name starts with a
567+ // negative number which is the ID of the run; e.g., "-2147483648_jobname.txt".
568+ func legacyJobLogFilenameRegexp (job shared.Job ) * regexp.Regexp {
569+ sanitizedJobName := getJobNameForLogFilename (job .Name )
570+ re := fmt .Sprintf (`^-\d+_%s\.txt$` , regexp .QuoteMeta (sanitizedJobName ))
561571 return regexp .MustCompile (re )
562572}
563573
564574func stepLogFilenameRegexp (job shared.Job , step shared.Step ) * regexp.Regexp {
565575 sanitizedJobName := getJobNameForLogFilename (job .Name )
566- re := fmt .Sprintf (`^%s\/%d_.*\.txt` , regexp .QuoteMeta (sanitizedJobName ), step .Number )
576+ re := fmt .Sprintf (`^%s\/%d_.*\.txt$ ` , regexp .QuoteMeta (sanitizedJobName ), step .Number )
567577 return regexp .MustCompile (re )
568578}
569579
@@ -662,24 +672,29 @@ func truncateAsUTF16(str string, max int) string {
662672// where the ID can apparently be negative.
663673func attachRunLog (rlz * zip.Reader , jobs []shared.Job ) {
664674 for i , job := range jobs {
665- re := jobLogFilenameRegexp (job )
666- for _ , file := range rlz .File {
667- if re .MatchString (file .Name ) {
668- jobs [i ].Log = file
669- break
670- }
675+ // As a highest priority, we try to use the step logs first. We have seen zips that surprisingly contain
676+ // step logs, normal job logs and legacy job logs. In this case, both job logs would be ignored. We have
677+ // never seen a zip containing both job logs and no step logs, however, it may be possible. In that case
678+ // let's prioritise the normal log over the legacy one.
679+ jobLog := matchFileInZIPArchive (rlz , jobLogFilenameRegexp (job ))
680+ if jobLog == nil {
681+ jobLog = matchFileInZIPArchive (rlz , legacyJobLogFilenameRegexp (job ))
671682 }
683+ jobs [i ].Log = jobLog
672684
673685 for j , step := range job .Steps {
674- re := stepLogFilenameRegexp (job , step )
675- for _ , file := range rlz .File {
676- if re .MatchString (file .Name ) {
677- jobs [i ].Steps [j ].Log = file
678- break
679- }
680- }
686+ jobs [i ].Steps [j ].Log = matchFileInZIPArchive (rlz , stepLogFilenameRegexp (job , step ))
687+ }
688+ }
689+ }
690+
691+ func matchFileInZIPArchive (zr * zip.Reader , re * regexp.Regexp ) * zip.File {
692+ for _ , file := range zr .File {
693+ if re .MatchString (file .Name ) {
694+ return file
681695 }
682696 }
697+ return nil
683698}
684699
685700func displayRunLog (w io.Writer , jobs []shared.Job , failed bool ) error {
0 commit comments