Parcourir la source

Only do Seek if there is an EOF in the perf fetcher

This is to handle the case where we have a file that is smaller than the
perf.data header, but is still (or can be converted in another way) a
valid profile.proto.
Wade Simba Khadder il y a 8 ans
Parent
révision
fe37e1287e
1 fichiers modifiés avec 6 ajouts et 6 suppressions
  1. 6
    6
      internal/driver/fetch.go

+ 6
- 6
internal/driver/fetch.go Voir le fichier

@@ -395,12 +395,12 @@ func profileProtoReader(path string, ui plugin.UI) (io.ReadCloser, error) {
395 395
 	// with the string PERFILE2.
396 396
 	perfHeader := []byte("PERFILE2")
397 397
 	actualHeader := make([]byte, len(perfHeader))
398
-	_, readErr := sourceFile.Read(actualHeader)
399
-	_, seekErr := sourceFile.Seek(0, 0)
400
-	if seekErr != nil {
401
-		return nil, seekErr
402
-	}
403
-	if readErr != nil && readErr != io.EOF{
398
+	if _, readErr := sourceFile.Read(actualHeader); readErr == io.EOF {
399
+		_, seekErr := sourceFile.Seek(0, 0)
400
+		if seekErr != nil {
401
+			return nil, seekErr
402
+		}
403
+	} else if readErr != nil {
404 404
 		return nil, readErr
405 405
 	}
406 406
 	if bytes.Equal(actualHeader, perfHeader) {