Skip to content

Commit 2b4bb67

Browse files
committed
feat: pass added and removed attachments to the backend
1 parent 0a29e3e commit 2b4bb67

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

src/backends/sentry_backend_crashpad.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,30 @@ crashpad_backend_prune_database(sentry_backend_t *backend)
661661
crashpad::PruneCrashReportDatabase(data->db, &condition);
662662
}
663663

664+
#if defined(SENTRY_PLATFORM_WINDOWS) || defined(SENTRY_PLATFORM_LINUX)
665+
static void
666+
crashpad_backend_add_attachment(
667+
sentry_backend_t *backend, const sentry_path_t *attachment)
668+
{
669+
auto *data = static_cast<crashpad_state_t *>(backend->data);
670+
if (!data->client) {
671+
return;
672+
}
673+
data->client->AddAttachment(base::FilePath(attachment->path));
674+
}
675+
676+
static void
677+
crashpad_backend_remove_attachment(
678+
sentry_backend_t *backend, const sentry_path_t *attachment)
679+
{
680+
auto *data = static_cast<crashpad_state_t *>(backend->data);
681+
if (!data->client) {
682+
return;
683+
}
684+
data->client->RemoveAttachment(base::FilePath(attachment->path));
685+
}
686+
#endif
687+
664688
sentry_backend_t *
665689
sentry__backend_new(void)
666690
{
@@ -688,6 +712,10 @@ sentry__backend_new(void)
688712
backend->user_consent_changed_func = crashpad_backend_user_consent_changed;
689713
backend->get_last_crash_func = crashpad_backend_last_crash;
690714
backend->prune_database_func = crashpad_backend_prune_database;
715+
#if defined(SENTRY_PLATFORM_WINDOWS) || defined(SENTRY_PLATFORM_LINUX)
716+
backend->add_attachment_func = crashpad_backend_add_attachment;
717+
backend->remove_attachment_func = crashpad_backend_remove_attachment;
718+
#endif
691719
backend->data = data;
692720
backend->can_capture_after_shutdown = true;
693721

src/sentry_backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ struct sentry_backend_s {
2525
void (*user_consent_changed_func)(sentry_backend_t *);
2626
uint64_t (*get_last_crash_func)(sentry_backend_t *);
2727
void (*prune_database_func)(sentry_backend_t *);
28+
void (*add_attachment_func)(sentry_backend_t *, const sentry_path_t *);
29+
void (*remove_attachment_func)(sentry_backend_t *, const sentry_path_t *);
2830
void *data;
2931
// Whether this backend still runs after shutdown_func was called.
3032
bool can_capture_after_shutdown;

src/sentry_core.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,37 +1418,61 @@ sentry_capture_minidump_n(const char *path, size_t path_len)
14181418
void
14191419
sentry_add_attachment(const char *path)
14201420
{
1421+
sentry_path_t *attachment = sentry__path_from_str(path);
1422+
SENTRY_WITH_OPTIONS (options) {
1423+
if (options->backend && options->backend->add_attachment_func) {
1424+
options->backend->add_attachment_func(options->backend, attachment);
1425+
}
1426+
}
14211427
SENTRY_WITH_SCOPE_MUT (scope) {
14221428
sentry__attachment_add(
1423-
&scope->attachments, sentry__path_from_str(path), ATTACHMENT, NULL);
1429+
&scope->attachments, attachment, ATTACHMENT, NULL);
14241430
}
14251431
}
14261432

14271433
void
14281434
sentry_remove_attachment(const char *path)
14291435
{
1436+
sentry_path_t *attachment = sentry__path_from_str(path);
1437+
SENTRY_WITH_OPTIONS (options) {
1438+
if (options->backend && options->backend->remove_attachment_func) {
1439+
options->backend->remove_attachment_func(
1440+
options->backend, attachment);
1441+
}
1442+
}
14301443
SENTRY_WITH_SCOPE_MUT (scope) {
1431-
sentry__attachment_remove(
1432-
&scope->attachments, sentry__path_from_str(path));
1444+
sentry__attachment_remove(&scope->attachments, attachment);
14331445
}
14341446
}
14351447

14361448
#ifdef SENTRY_PLATFORM_WINDOWS
14371449
void
14381450
sentry_add_attachmentw(const wchar_t *path)
14391451
{
1452+
sentry_path_t *attachment = sentry__path_from_wstr(path);
1453+
SENTRY_WITH_OPTIONS (options) {
1454+
if (options->backend && options->backend->add_attachment_func) {
1455+
options->backend->add_attachment_func(options->backend, attachment);
1456+
}
1457+
}
14401458
SENTRY_WITH_SCOPE_MUT (scope) {
1441-
sentry__attachment_add(&scope->attachments,
1442-
sentry__path_from_wstr(path), ATTACHMENT, NULL);
1459+
sentry__attachment_add(
1460+
&scope->attachments, attachment, ATTACHMENT, NULL);
14431461
}
14441462
}
14451463

14461464
void
14471465
sentry_remove_attachmentw(const wchar_t *path)
14481466
{
1467+
sentry_path_t *attachment = sentry__path_from_wstr(path);
1468+
SENTRY_WITH_OPTIONS (options) {
1469+
if (options->backend && options->backend->remove_attachment_func) {
1470+
options->backend->remove_attachment_func(
1471+
options->backend, attachment);
1472+
}
1473+
}
14491474
SENTRY_WITH_SCOPE_MUT (scope) {
1450-
sentry__attachment_remove(
1451-
&scope->attachments, sentry__path_from_wstr(path));
1475+
sentry__attachment_remove(&scope->attachments, attachment);
14521476
}
14531477
}
14541478
#endif

0 commit comments

Comments
 (0)