浏览代码

Removes error in the return statement of isPerfData

Wade Simba Khadder 8 年前
父节点
当前提交
f6af5cf4ae
共有 1 个文件被更改,包括 7 次插入11 次删除
  1. 7
    11
      internal/driver/fetch.go

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

358
 		}
358
 		}
359
 		f, err = fetchURL(sourceURL, timeout)
359
 		f, err = fetchURL(sourceURL, timeout)
360
 		src = sourceURL
360
 		src = sourceURL
361
-	} else if isPerf, isPerfErr := isPerfFile(source); isPerf {
362
-		// Since the if statement is a new scope, if isPerfErr is named
363
-		// err, it shadows the err in the return, and does not compile.
364
-		if isPerfErr != nil {
365
-			return nil, "", isPerfErr
366
-		}
361
+	} else if isPerfFile(source) {
367
 		f, err = convertPerfData(source, ui)
362
 		f, err = convertPerfData(source, ui)
368
 	} else {
363
 	} else {
369
 		f, err = os.Open(source)
364
 		f, err = os.Open(source)
388
 	return resp.Body, nil
383
 	return resp.Body, nil
389
 }
384
 }
390
 
385
 
391
-// isPerfFile checks if a file is in perf.data format.
392
-func isPerfFile(path string) (bool, error) {
386
+// isPerfFile checks if a file is in perf.data format. It also returns false
387
+// if it encounters an error during the check.
388
+func isPerfFile(path string) bool {
393
 	sourceFile, openErr := os.Open(path)
389
 	sourceFile, openErr := os.Open(path)
394
 	if openErr != nil {
390
 	if openErr != nil {
395
-		return false, openErr
391
+		return false
396
 	}
392
 	}
397
 	defer sourceFile.Close()
393
 	defer sourceFile.Close()
398
 
394
 
401
 	perfHeader := []byte("PERFILE2")
397
 	perfHeader := []byte("PERFILE2")
402
 	actualHeader := make([]byte, len(perfHeader))
398
 	actualHeader := make([]byte, len(perfHeader))
403
 	if _, readErr := sourceFile.Read(actualHeader); readErr != nil {
399
 	if _, readErr := sourceFile.Read(actualHeader); readErr != nil {
404
-		return false, readErr
400
+		return false
405
 	}
401
 	}
406
-	return bytes.Equal(actualHeader, perfHeader), nil
402
+	return bytes.Equal(actualHeader, perfHeader)
407
 }
403
 }
408
 
404
 
409
 // convertPerfData converts the file at path which should be in perf.data format
405
 // convertPerfData converts the file at path which should be in perf.data format