diff options
| author | Paul Buetow <paul@buetow.org> | 2025-04-11 22:29:04 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-04-11 22:29:04 +0300 |
| commit | 3917a7a6157ce553781dc240129cb1184505cf63 (patch) | |
| tree | e609ec2c92491cfc4aab320237087288fc9c08eb /internal/flamegraph | |
| parent | 820fc45592db2af782d47db82755be34f16fb21c (diff) | |
delete file if empty
Diffstat (limited to 'internal/flamegraph')
| -rw-r--r-- | internal/flamegraph/tool.go | 16 |
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 +} |
