@@ -19,7 +19,6 @@ import (
19
19
"flag"
20
20
"github.com/google/gapid/core/app"
21
21
"github.com/google/gapid/core/log"
22
- "io/ioutil"
23
22
"os"
24
23
)
25
24
@@ -50,25 +49,23 @@ func (verb *createGraphVisualizationVerb) Run(ctx context.Context, flags flag.Fl
50
49
51
50
graphVisualization , err := client .GetGraphVisualization (ctx , capture )
52
51
if err != nil {
53
- return log .Errf (ctx , err , "ExportCapture (%v)" , capture )
52
+ return log .Errf (ctx , err , "GetGraphVisualization (%v)" , capture )
54
53
}
55
54
56
55
filePath := verb .Out
57
56
if filePath == "" {
58
57
filePath = "graph_visualization.dot"
59
58
}
60
59
61
- _ , err = os .Stat (filePath )
62
- if os .IsNotExist (err ) {
63
- file , err := os .Create (filePath )
64
- if err != nil {
65
- log .Errf (ctx , err , "Creating file (%v)" , filePath )
66
- }
67
- defer file .Close ()
60
+ file , err := os .Create (filePath )
61
+ if err != nil {
62
+ return log .Errf (ctx , err , "Creating file (%v)" , filePath )
68
63
}
64
+ defer file .Close ()
69
65
70
- if err := ioutil .WriteFile (filePath , []byte (graphVisualization ), 0666 ); err != nil {
71
- return log .Errf (ctx , err , "Writing file: %v" , filePath )
66
+ bytesWritten , err := file .Write (graphVisualization )
67
+ if err != nil {
68
+ return log .Errf (ctx , err , "Error after writing %d bytes to file" , bytesWritten )
72
69
}
73
70
return nil
74
71
}
0 commit comments