File tree Expand file tree Collapse file tree 5 files changed +65
-0
lines changed
Expand file tree Collapse file tree 5 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,17 @@ sentry__path_get_size(const sentry_path_t *path)
267267 }
268268}
269269
270+ time_t
271+ sentry__path_get_mtime (const sentry_path_t * path )
272+ {
273+ struct stat buf ;
274+ if (stat (path -> path , & buf ) == 0 ) {
275+ return (time_t )buf .st_mtime ;
276+ } else {
277+ return 0 ;
278+ }
279+ }
280+
270281sentry_path_t *
271282sentry__path_append_str (const sentry_path_t * base , const char * suffix )
272283{
Original file line number Diff line number Diff line change @@ -329,6 +329,17 @@ sentry__path_get_size(const sentry_path_t *path)
329329 }
330330}
331331
332+ time_t
333+ sentry__path_get_mtime (const sentry_path_t * path )
334+ {
335+ struct _stat buf ;
336+ if (_wstat (path -> path , & buf ) == 0 ) {
337+ return (time_t )buf .st_mtime ;
338+ } else {
339+ return 0 ;
340+ }
341+ }
342+
332343sentry_path_t *
333344sentry__path_append_str (const sentry_path_t * base , const char * suffix )
334345{
Original file line number Diff line number Diff line change 44#include "sentry_boot.h"
55
66#include <stdio.h>
7+ #include <time.h>
78
89#ifdef SENTRY_PLATFORM_WINDOWS
910typedef wchar_t sentry_pathchar_t ;
@@ -152,6 +153,12 @@ int sentry__path_touch(const sentry_path_t *path);
152153 */
153154size_t sentry__path_get_size (const sentry_path_t * path );
154155
156+ /**
157+ * This will return the last modification time of the file at `path`, or 0 on
158+ * failure.
159+ */
160+ time_t sentry__path_get_mtime (const sentry_path_t * path );
161+
155162/**
156163 * This will read all the content of `path` into a newly allocated buffer, and
157164 * write its size into `size_out`.
Original file line number Diff line number Diff line change 22#include "sentry_string.h"
33#include "sentry_testsupport.h"
44
5+ #ifdef SENTRY_PLATFORM_WINDOWS
6+ # include <windows.h>
7+ # define sleep_s (SECONDS ) Sleep(SECONDS * 1000)
8+ #else
9+ # include <unistd.h>
10+ # define sleep_s (SECONDS ) sleep(SECONDS)
11+ #endif
12+
513SENTRY_TEST (recursive_paths )
614{
715 sentry_path_t * base = sentry__path_from_str (SENTRY_TEST_PATH_PREFIX ".foo" );
@@ -240,3 +248,30 @@ SENTRY_TEST(path_directory)
240248 sentry__path_free (path_1 );
241249 sentry__path_free (path_2 );
242250}
251+
252+ SENTRY_TEST (path_mtime )
253+ {
254+ sentry_path_t * path
255+ = sentry__path_from_str (SENTRY_TEST_PATH_PREFIX "foo.txt" );
256+ TEST_ASSERT (!!path );
257+
258+ TEST_CHECK (sentry__path_remove (path ) == 0 );
259+ TEST_CHECK (!sentry__path_is_file (path ));
260+ TEST_CHECK (sentry__path_get_mtime (path ) <= 0 );
261+
262+ sentry__path_touch (path );
263+ TEST_CHECK (sentry__path_is_file (path ));
264+
265+ int before = sentry__path_get_mtime (path );
266+ TEST_CHECK (before > 0 );
267+
268+ sleep_s (1 );
269+
270+ sentry__path_write_buffer (path , "after" , 5 );
271+ int after = sentry__path_get_mtime (path );
272+ TEST_CHECK (after > 0 );
273+ TEST_CHECK (before < after );
274+
275+ sentry__path_remove (path );
276+ sentry__path_free (path );
277+ }
Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ XX(path_from_str_n_wo_null_termination)
9292XX(path_from_str_null)
9393XX(path_joining_unix)
9494XX(path_joining_windows)
95+ XX(path_mtime)
9596XX(path_relative_filename)
9697XX(procmaps_parser)
9798XX(propagation_context_init)
You can’t perform that action at this time.
0 commit comments