|
@@ -358,12 +358,7 @@ func fetch(source string, duration, timeout time.Duration, ui plugin.UI) (p *pro
|
358
|
358
|
}
|
359
|
359
|
f, err = fetchURL(sourceURL, timeout)
|
360
|
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
|
362
|
f, err = convertPerfData(source, ui)
|
368
|
363
|
} else {
|
369
|
364
|
f, err = os.Open(source)
|
|
@@ -388,11 +383,12 @@ func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
|
388
|
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
|
389
|
sourceFile, openErr := os.Open(path)
|
394
|
390
|
if openErr != nil {
|
395
|
|
- return false, openErr
|
|
391
|
+ return false
|
396
|
392
|
}
|
397
|
393
|
defer sourceFile.Close()
|
398
|
394
|
|
|
@@ -401,9 +397,9 @@ func isPerfFile(path string) (bool, error) {
|
401
|
397
|
perfHeader := []byte("PERFILE2")
|
402
|
398
|
actualHeader := make([]byte, len(perfHeader))
|
403
|
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
|
405
|
// convertPerfData converts the file at path which should be in perf.data format
|