summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/flamegraph/tool.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/internal/flamegraph/tool.go b/internal/flamegraph/tool.go
index 0ce33e3..3719b0a 100644
--- a/internal/flamegraph/tool.go
+++ b/internal/flamegraph/tool.go
@@ -44,6 +44,8 @@ func NewTool(collapsedFile string) (Tool, error) {
}
func (t Tool) WriteSVG() error {
+ defer deleteFileIfEmpty(t.outFile)
+
if _, err := os.Stat(t.outFile); err == nil {
fmt.Println(t.outFile, "already exists!")
return nil
@@ -92,3 +94,17 @@ func decompress(compressedFile string) (string, error) {
return decompressedFile, nil
}
+
+func deleteFileIfEmpty(file string) error {
+ if _, err := os.Stat(file); err == nil {
+ fileInfo, err := os.Stat(file)
+ if err != nil {
+ return err
+ }
+ if fileInfo.Size() == 0 {
+ fmt.Println("Deleting", file, "as it is empty")
+ return os.Remove(file)
+ }
+ }
+ return nil
+}