File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,19 @@ sentry__path_remove_all(const sentry_path_t *path)
7979 return sentry__path_remove (path );
8080}
8181
82+ size_t
83+ sentry__path_get_dir_size (const sentry_path_t * path )
84+ {
85+ size_t total = 0 ;
86+ sentry_pathiter_t * iter = sentry__path_iter_directory (path );
87+ const sentry_path_t * entry ;
88+ while (iter && (entry = sentry__pathiter_next (iter )) != NULL ) {
89+ total += sentry__path_get_size (entry );
90+ }
91+ sentry__pathiter_free (iter );
92+ return total ;
93+ }
94+
8295sentry_filelock_t *
8396sentry__filelock_new (sentry_path_t * path )
8497{
Original file line number Diff line number Diff line change @@ -183,6 +183,12 @@ int sentry__path_touch(const sentry_path_t *path);
183183 */
184184size_t sentry__path_get_size (const sentry_path_t * path );
185185
186+ /**
187+ * This will return the total size of all files in the directory at `path`,
188+ * or 0 if the directory does not exist or is empty.
189+ */
190+ size_t sentry__path_get_dir_size (const sentry_path_t * path );
191+
186192/**
187193 * This will return the last modification time of the file at `path`, or 0 on
188194 * failure.
Original file line number Diff line number Diff line change @@ -340,6 +340,36 @@ SENTRY_TEST(path_rename)
340340 sentry__path_free (src );
341341}
342342
343+ SENTRY_TEST (path_dir_size )
344+ {
345+ sentry_path_t * dir
346+ = sentry__path_from_str (SENTRY_TEST_PATH_PREFIX ".dir-size" );
347+ TEST_ASSERT (!!dir );
348+
349+ sentry__path_remove_all (dir );
350+
351+ TEST_CHECK (sentry__path_get_dir_size (dir ) == 0 );
352+
353+ sentry__path_create_dir_all (dir );
354+
355+ sentry_path_t * file_a = sentry__path_join_str (dir , "a.txt" );
356+ TEST_ASSERT (!!file_a );
357+ sentry__path_write_buffer (file_a , "hello" , 5 );
358+
359+ sentry_path_t * file_b = sentry__path_join_str (dir , "b.txt" );
360+ TEST_ASSERT (!!file_b );
361+ sentry__path_write_buffer (file_b , "world!" , 6 );
362+
363+ TEST_CHECK (sentry__path_get_dir_size (dir ) == 11 );
364+
365+ TEST_CHECK (sentry__path_get_dir_size (file_a ) == 0 );
366+
367+ sentry__path_remove_all (dir );
368+ sentry__path_free (file_b );
369+ sentry__path_free (file_a );
370+ sentry__path_free (dir );
371+ }
372+
343373SENTRY_TEST (path_copy )
344374{
345375#if defined(SENTRY_PLATFORM_NX )
Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ XX(page_allocator)
157157XX(path_basics)
158158XX(path_copy)
159159XX(path_current_exe)
160+ XX(path_dir_size)
160161XX(path_directory)
161162XX(path_from_str_n_wo_null_termination)
162163XX(path_from_str_null)
You can’t perform that action at this time.
0 commit comments