Преглед изворни кода

Split source filepath cleanup from file opening

Reports want to use trimmed paths, not the location in the current
filesystem which may be very verbose.
Raul Silvera пре 9 година
родитељ
комит
4dfde1723a
1 измењених фајлова са 6 додато и 7 уклоњено
  1. 6
    7
      internal/report/source.go

+ 6
- 7
internal/report/source.go Прегледај датотеку

@@ -338,7 +338,8 @@ func printPageClosing(w io.Writer) {
338 338
 // file and annotates it with the samples in fns. Returns the sources
339 339
 // as nodes, using the info.name field to hold the source code.
340 340
 func getFunctionSource(fun, file, sourcePath string, fns graph.Nodes, start, end int) (graph.Nodes, string, error) {
341
-	f, file, err := openSourceFile(file, sourcePath)
341
+	file = trimPath(file)
342
+	f, err := openSourceFile(file, sourcePath)
342 343
 	if err != nil {
343 344
 		return nil, file, err
344 345
 	}
@@ -433,12 +434,10 @@ func getMissingFunctionSource(filename string, asm map[int]graph.Nodes, start, e
433 434
 // profile. File names in a profile after often relative paths, so
434 435
 // search them in each of the paths in searchPath (or CWD by default),
435 436
 // and their parents.
436
-func openSourceFile(path, searchPath string) (*os.File, string, error) {
437
-	path = trimPath(path)
438
-
437
+func openSourceFile(path, searchPath string) (*os.File, error) {
439 438
 	if filepath.IsAbs(path) {
440 439
 		f, err := os.Open(path)
441
-		return f, path, err
440
+		return f, err
442 441
 	}
443 442
 
444 443
 	// Scan each component of the path
@@ -447,7 +446,7 @@ func openSourceFile(path, searchPath string) (*os.File, string, error) {
447 446
 		for {
448 447
 			filename := filepath.Join(dir, path)
449 448
 			if f, err := os.Open(filename); err == nil {
450
-				return f, filename, nil
449
+				return f, nil
451 450
 			}
452 451
 			parent := filepath.Dir(dir)
453 452
 			if parent == dir {
@@ -457,7 +456,7 @@ func openSourceFile(path, searchPath string) (*os.File, string, error) {
457 456
 		}
458 457
 	}
459 458
 
460
-	return nil, "", fmt.Errorf("Could not find file %s on path %s", path, searchPath)
459
+	return nil, fmt.Errorf("Could not find file %s on path %s", path, searchPath)
461 460
 }
462 461
 
463 462
 // trimPath cleans up a path by removing prefixes that are commonly