Browse Source

Use deferDeleteTempFile instead of DeleteOnClose

Wade Simba Khadder 8 years ago
parent
commit
c4c7a25e47
2 changed files with 4 additions and 24 deletions
  1. 4
    3
      internal/driver/fetch.go
  2. 0
    21
      internal/driver/tempfile.go

+ 4
- 3
internal/driver/fetch.go View File

@@ -411,10 +411,9 @@ func profileProtoReader(path string, ui plugin.UI) (io.ReadCloser, error) {
411 411
 		}
412 412
 		profileFile, openErr := os.Open(profileFilePath)
413 413
 		if openErr != nil {
414
-			os.Remove(profileFilePath)
415 414
 			return nil, openErr
416 415
 		}
417
-		return DeleteOnClose(profileFile), nil
416
+		return profileFile, nil
418 417
 	}
419 418
 	return sourceFile, nil
420 419
 }
@@ -431,8 +430,10 @@ func convertPerfData(perfPath string, ui plugin.UI) (string, error) {
431 430
 		return "", err
432 431
 	}
433 432
 	cmd := exec.Command("perf_to_profile", perfPath, profilePath)
433
+	// If perf_to_profile failed before generating the file, this defer
434
+	// is just a no-op.
435
+	deferDeleteTempFile(profilePath)
434 436
 	if err := cmd.Run(); err != nil {
435
-		os.Remove(profilePath)
436 437
 		return "", err
437 438
 	}
438 439
 	return profilePath, nil

+ 0
- 21
internal/driver/tempfile.go View File

@@ -42,27 +42,6 @@ func newTempFile(dir, prefix, suffix string) (*os.File, error) {
42 42
 	return os.Create(path)
43 43
 }
44 44
 
45
-type VolatileFile struct {
46
-	*os.File
47
-}
48
-
49
-func (file VolatileFile) Close() error {
50
-	if err := file.File.Close(); err != nil {
51
-		return err
52
-	}
53
-	if err := os.Remove(file.Name()); err != nil {
54
-		return err
55
-	}
56
-	return nil
57
-}
58
-
59
-// DeleteOnClose deletes file on Close().
60
-func DeleteOnClose(file *os.File) VolatileFile {
61
-	return VolatileFile {
62
-		File: file,
63
-	}
64
-}
65
-
66 45
 var tempFiles []string
67 46
 var tempFilesMu = sync.Mutex{}
68 47