diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 38 |
1 files changed, 18 insertions, 20 deletions
@@ -221,18 +221,6 @@ static void get_tracked_items(const char *tracked_dir, time_t age_sec, Buffer /* strcpy(data_filepath + data_filepath_length, dir->d_name); - strcpy(data_filepath + data_filepath_length + filename_len, "/synced"); - if(file_get_content(data_filepath, &file_data, &file_size) != 0) { - fprintf(stderr, "Failed to read the content of file %s\n", data_filepath); - continue; - } - - time_t synced_time = 0; - sscanf(file_data, "%ld", &synced_time); - free(file_data); - if(time_now - synced_time > age_sec) - continue; - strcpy(data_filepath + data_filepath_length + filename_len, "/updated"); if(file_get_content(data_filepath, &file_data, &file_size) != 0) { fprintf(stderr, "Failed to read the content of file %s\n", data_filepath); @@ -697,14 +685,21 @@ const char* path_get_filename(const char *filepath) { return filepath; } -static void command_cleanup(int argc, char **argv, const char *rss_config_dir, const char *html_config_dir) { - if(argc < 1) - usage_cleanup(); +static int compare_tracked_item(const void *a, const void *b) { + const TrackedItemData *list_data_a = a; + const TrackedItemData *list_data_b = b; + return list_data_a->updated_time - list_data_b->updated_time; +} - time_t days = strtol(argv[0], NULL, 0); - if(errno || days < 0) { - fprintf(stderr, "Invalid value for days argument %s, expected a positive number\n", argv[0]); - return; +static void command_cleanup(int argc, char **argv, const char *rss_config_dir, const char *html_config_dir) { + time_t days = 0; + if(argc >= 1) { + errno = 0; + days = strtol(argv[0], NULL, 0); + if(errno || days < 0) { + fprintf(stderr, "Invalid value for days argument %s, expected a positive number\n", argv[0]); + usage_cleanup(); + } } char rss_tracked_dir[PATH_MAX]; @@ -719,12 +714,15 @@ static void command_cleanup(int argc, char **argv, const char *rss_config_dir, c buffer_init(&tracked_items); int num_rss_items = 0; - time_t age_sec = 60 * 60 * 24 * days; + const time_t age_sec = 60 * 60 * 24 * days; get_tracked_items(rss_tracked_dir, age_sec, &tracked_items); num_rss_items = buffer_get_size(&tracked_items, sizeof(TrackedItemData)); get_tracked_items(html_tracked_dir, age_sec, &tracked_items); int num_tracked_items = buffer_get_size(&tracked_items, sizeof(TrackedItemData)); + qsort(tracked_items.data, num_rss_items, sizeof(TrackedItemData), compare_tracked_item); + qsort((TrackedItemData*)tracked_items.data + num_rss_items, num_tracked_items - num_rss_items, sizeof(TrackedItemData), compare_tracked_item); + TrackedItemData *list_begin = buffer_begin(&tracked_items); TrackedItemData *list_it = list_begin; TrackedItemData *list_end = buffer_end(&tracked_items); |