瀏覽代碼

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 8 年之前
父節點
當前提交
fe37e1287e
共有 1 個檔案被更改,包括 6 行新增6 行删除
  1. 6
    6
      internal/driver/fetch.go

+ 6
- 6
internal/driver/fetch.go 查看文件

@@ -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) {