-
-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathsentry_path.c
More file actions
115 lines (105 loc) · 2.44 KB
/
sentry_path.c
File metadata and controls
115 lines (105 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "sentry_path.h"
#include "sentry_alloc.h"
sentry_path_t *
sentry__path_from_str_n(const char *s, size_t s_len)
{
char *path = sentry__string_clone_n(s, s_len);
if (!path) {
return NULL;
}
// NOTE: function will free `path` on error
return sentry__path_from_str_owned(path);
}
sentry_path_t *
sentry__path_from_str(const char *s)
{
return s ? sentry__path_from_str_n(s, strlen(s)) : NULL;
}
sentry_path_t *
sentry__path_from_str_owned(char *s)
{
sentry_path_t *rv = SENTRY_MAKE(sentry_path_t);
if (!rv) {
sentry_free(s);
return NULL;
}
rv->path = s;
#ifdef SENTRY_PLATFORM_WINDOWS
rv->path_w = sentry__string_to_wstr(s);
if (!rv->path_w) {
sentry__path_free(rv);
return NULL;
}
#endif
return rv;
}
void
sentry__path_free(sentry_path_t *path)
{
if (!path) {
return;
}
#ifdef SENTRY_PLATFORM_WINDOWS
sentry_free(path->path_w);
#endif
sentry_free(path->path);
sentry_free(path);
}
bool
sentry__path_eq(const sentry_path_t *path_a, const sentry_path_t *path_b)
{
size_t i = 0;
while (path_a->path[i] == path_b->path[i]) {
if (path_a->path[i] == (char)0) {
return true;
}
i++;
}
return false;
}
int
sentry__path_remove_all(const sentry_path_t *path)
{
if (sentry__path_is_dir(path)) {
sentry_pathiter_t *piter = sentry__path_iter_directory(path);
if (piter) {
const sentry_path_t *p;
while ((p = sentry__pathiter_next(piter)) != NULL) {
sentry__path_remove_all(p);
}
sentry__pathiter_free(piter);
}
}
return sentry__path_remove(path);
}
size_t
sentry__path_get_dir_size(const sentry_path_t *path)
{
size_t total = 0;
sentry_pathiter_t *iter = sentry__path_iter_directory(path);
const sentry_path_t *entry;
while (iter && (entry = sentry__pathiter_next(iter)) != NULL) {
total += sentry__path_get_size(entry);
}
sentry__pathiter_free(iter);
return total;
}
sentry_filelock_t *
sentry__filelock_new(sentry_path_t *path)
{
sentry_filelock_t *rv = SENTRY_MAKE(sentry_filelock_t);
if (!rv) {
sentry__path_free(path);
return NULL;
}
rv->path = path;
rv->is_locked = false;
return rv;
}
void
sentry__filelock_free(sentry_filelock_t *lock)
{
sentry__filelock_unlock(lock);
sentry__path_free(lock->path);
sentry_free(lock);
}