@@ -99,29 +99,40 @@ sentry__run_free(sentry_run_t *run)
9999 sentry_free (run );
100100}
101101
102- bool
103- sentry__run_write_envelope (
104- const sentry_run_t * run , const sentry_envelope_t * envelope )
102+ static sentry_path_t *
103+ write_envelope (const sentry_path_t * path , const sentry_envelope_t * envelope )
105104{
105+ // 37 for the uuid, 9 for the `.envelope` suffix
106+ char envelope_filename [37 + 9 ];
106107 sentry_uuid_t event_id = sentry__envelope_get_event_id (envelope );
107- char * envelope_filename = sentry__uuid_as_filename (& event_id , ".envelope" );
108+ sentry_uuid_as_string (& event_id , envelope_filename );
109+ strcpy (& envelope_filename [36 ], ".envelope" );
108110
109- sentry_path_t * output_path
110- = sentry__path_join_str (run -> run_path , envelope_filename );
111- sentry_free (envelope_filename );
111+ sentry_path_t * output_path = sentry__path_join_str (path , envelope_filename );
112112 if (!output_path ) {
113- return false ;
113+ return NULL ;
114114 }
115115
116116 int rv = sentry_envelope_write_to_path (envelope , output_path );
117- sentry__path_free (output_path );
118-
119117 if (rv ) {
120118 SENTRY_WARN ("writing envelope to file failed" );
119+ sentry__path_free (output_path );
120+ return NULL ;
121121 }
122122
123- // the `write_to_path` returns > 0 on failure, but we would like a real bool
124- return !rv ;
123+ return output_path ;
124+ }
125+
126+ bool
127+ sentry__run_write_envelope (
128+ const sentry_run_t * run , const sentry_envelope_t * envelope )
129+ {
130+ sentry_path_t * output_path = write_envelope (run -> run_path , envelope );
131+ if (output_path ) {
132+ sentry__path_free (output_path );
133+ return true;
134+ }
135+ return false;
125136}
126137
127138sentry_path_t *
@@ -134,25 +145,7 @@ sentry__run_write_feedback(
134145 return NULL ;
135146 }
136147
137- sentry_uuid_t event_id = sentry__envelope_get_event_id (envelope );
138- char * envelope_filename = sentry__uuid_as_filename (& event_id , ".envelope" );
139-
140- sentry_path_t * output_path
141- = sentry__path_join_str (run -> feedback_path , envelope_filename );
142- sentry_free (envelope_filename );
143- if (!output_path ) {
144- return NULL ;
145- }
146-
147- int rv = sentry_envelope_write_to_path (envelope , output_path );
148- sentry__path_free (output_path );
149-
150- if (rv ) {
151- SENTRY_WARN ("writing envelope to file failed" );
152- }
153-
154- // the `write_to_path` returns > 0 on failure, but we would like a real bool
155- return !rv ? output_path : NULL ;
148+ return write_envelope (run -> feedback_path , envelope );
156149}
157150
158151bool
0 commit comments