diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/html.c | 7 | ||||
-rw-r--r-- | src/rss.c | 7 |
2 files changed, 12 insertions, 2 deletions
@@ -378,6 +378,10 @@ int add_html(const char *name, const char *url, char *html_config_dir, char *pro return result; } +static int int_min(int a, int b) { + return a < b ? a : b; +} + static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *download_items_buffer, TrackedHtml *tracked_html, char *html_tracked_dir, const char *download_dir) { const char *home_dir = get_home_dir(); @@ -398,6 +402,7 @@ static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *d DownloadItemsData *download_items_it = buffer_end(download_items_buffer); DownloadItemsData *download_items_end = buffer_begin(download_items_buffer); + const size_t num_items_to_download = int_min(download_items_it - download_items_end, MAX_UPDATE_ITEMS); download_items_it--; download_items_end--; int download_item_index = 0; @@ -436,7 +441,7 @@ static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *d added_download_items[download_item_index] = download_items_it; // TODO: What if the download is so fast two items have the same timestamp? Maybe substract by MAX_UPDATE_ITEMS and then add 1 each loop, // or use milliseconds/microseconds timestamps? - timestamps[download_item_index] = time(NULL); + timestamps[download_item_index] = time(NULL) - num_items_to_download + (download_item_index + 1); ++download_item_index; } @@ -480,6 +480,10 @@ static int rss_parse_sync_callback(const char *title, const char *link, void *us return 0; } +static int int_min(int a, int b) { + return a < b ? a : b; +} + static int add_torrents_in_reverse(TransmissionSession *transmission_session, Buffer *download_items_buffer, TrackedRss *tracked_rss, char *rss_tracked_dir) { int result = 0; char *torrent_names[MAX_UPDATE_ITEMS]; @@ -491,6 +495,7 @@ static int add_torrents_in_reverse(TransmissionSession *transmission_session, Bu DownloadItemsData *download_items_it = buffer_end(download_items_buffer); DownloadItemsData *download_items_end = buffer_begin(download_items_buffer); + const size_t num_items_to_download = int_min(download_items_it - download_items_end, MAX_UPDATE_ITEMS); download_items_it--; download_items_end--; int torrent_name_index = 0; @@ -502,7 +507,7 @@ static int add_torrents_in_reverse(TransmissionSession *transmission_session, Bu break; } added_download_items[torrent_name_index] = download_items_it; - timestamps[torrent_name_index] = time(NULL); + timestamps[torrent_name_index] = time(NULL) - num_items_to_download + (torrent_name_index + 1); ++torrent_name_index; /* Show notification that download has started? */ } |