@@ -585,20 +585,23 @@ compare_cache_entries_newest_first(const void *a, const void *b)
585585 return 0 ;
586586}
587587
588- static const char *
589- extract_envelope_uuid ( const char * filename )
588+ static sentry_path_t *
589+ envelope_attachment_dir ( const sentry_path_t * cache_dir , const char * filename )
590590{
591591 uint64_t ts ;
592592 int count ;
593593 const char * uuid ;
594- if (sentry__parse_cache_filename (filename , & ts , & count , & uuid )) {
595- return uuid ;
596- }
597- size_t len = strlen ( filename ) ;
598- if ( len == 45 && strcmp ( filename + 36 , ".envelope" ) == 0 ) {
599- return filename ;
594+ if (! sentry__parse_cache_filename (filename , & ts , & count , & uuid )) {
595+ size_t len = strlen ( filename ) ;
596+ if ( len != 45 || strcmp ( filename + 36 , ".envelope" ) != 0 ) {
597+ return NULL ;
598+ }
599+ uuid = filename ;
600600 }
601- return NULL ;
601+ char uuid_buf [37 ];
602+ memcpy (uuid_buf , uuid , 36 );
603+ uuid_buf [36 ] = '\0' ;
604+ return sentry__path_join_str (cache_dir , uuid_buf );
602605}
603606
604607void
@@ -651,6 +654,17 @@ sentry__cleanup_cache(const sentry_options_t *options)
651654 }
652655 entries [entries_count ].mtime = sentry__path_get_mtime (entry );
653656 entries [entries_count ].size = sentry__path_get_size (entry );
657+
658+ const char * fname = sentry__path_filename (entry );
659+ if (fname ) {
660+ sentry_path_t * att_dir = envelope_attachment_dir (cache_dir , fname );
661+ if (att_dir ) {
662+ entries [entries_count ].size
663+ += sentry__path_get_dir_size (att_dir );
664+ sentry__path_free (att_dir );
665+ }
666+ }
667+
654668 entries_count ++ ;
655669 }
656670 sentry__pathiter_free (iter );
@@ -689,17 +703,11 @@ sentry__cleanup_cache(const sentry_options_t *options)
689703 if (should_prune ) {
690704 const char * fname = sentry__path_filename (entries [i ].path );
691705 if (fname ) {
692- const char * uuid = extract_envelope_uuid (fname );
693- if (uuid ) {
694- char uuid_buf [37 ];
695- memcpy (uuid_buf , uuid , 36 );
696- uuid_buf [36 ] = '\0' ;
697- sentry_path_t * att_dir
698- = sentry__path_join_str (cache_dir , uuid_buf );
699- if (att_dir ) {
700- sentry__path_remove_all (att_dir );
701- sentry__path_free (att_dir );
702- }
706+ sentry_path_t * att_dir
707+ = envelope_attachment_dir (cache_dir , fname );
708+ if (att_dir ) {
709+ sentry__path_remove_all (att_dir );
710+ sentry__path_free (att_dir );
703711 }
704712 }
705713 sentry__path_remove_all (entries [i ].path );
0 commit comments