diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-07-27 20:14:05 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-27 20:14:05 +0200 |
commit | ec5e3c06084ef9c4b7fd71e4bb04af3fbe77bed9 (patch) | |
tree | deb399105f1d752d8f97f13138ab9ad354df4bbd | |
parent | 01a6bc67e70600680a1bbf6b9b5d102192760ae4 (diff) |
Time of html items in json file should be the time of download finished, not the time of start of all downloads
-rw-r--r-- | src/html.c | 4 | ||||
-rw-r--r-- | src/rss.c | 4 | ||||
-rw-r--r-- | src/rss_html_common.c | 10 | ||||
-rw-r--r-- | src/rss_html_common.h | 2 | ||||
-rw-r--r-- | src/transmission.c | 2 |
5 files changed, 15 insertions, 7 deletions
@@ -335,6 +335,7 @@ static int plugin_list_sync_callback(const char *name, const char *url, void *us 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) { int result = 0; DownloadItemsData *added_download_items[MAX_UPDATE_ITEMS]; + long timestamps[MAX_UPDATE_ITEMS]; char item_dir[PATH_MAX]; const char *path_components[] = { download_dir, tracked_html->title }; @@ -375,6 +376,7 @@ static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *d break; added_download_items[download_item_index] = download_items_it; + timestamps[download_item_index] = time(NULL); ++download_item_index; } @@ -382,7 +384,7 @@ static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *d tracked_item.title = tracked_html->title; tracked_item.link = tracked_html->link; tracked_item.json_data = tracked_html->json_data; - result = tracked_item_update_latest(&tracked_item, html_tracked_dir, added_download_items, NULL, download_item_index); + result = tracked_item_update_latest(&tracked_item, html_tracked_dir, added_download_items, NULL, timestamps, download_item_index); buffer_deinit(&json_element_buffer); return result; @@ -470,6 +470,7 @@ static int add_torrents_in_reverse(TransmissionSession *transmission_session, Bu int result = 0; char *torrent_names[MAX_UPDATE_ITEMS]; DownloadItemsData *added_download_items[MAX_UPDATE_ITEMS]; + long timestamps[MAX_UPDATE_ITEMS]; Buffer json_element_buffer; buffer_init(&json_element_buffer); @@ -487,6 +488,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); ++torrent_name_index; /* Show notification that download has started? */ } @@ -495,7 +497,7 @@ static int add_torrents_in_reverse(TransmissionSession *transmission_session, Bu tracked_item.title = tracked_rss->title; tracked_item.link = tracked_rss->link; tracked_item.json_data = tracked_rss->json_data; - result = tracked_item_update_latest(&tracked_item, rss_tracked_dir, added_download_items, torrent_names, torrent_name_index); + result = tracked_item_update_latest(&tracked_item, rss_tracked_dir, added_download_items, torrent_names, timestamps, torrent_name_index); for(int i = 0; i < torrent_name_index; ++i) { free(torrent_names[i]); diff --git a/src/rss_html_common.c b/src/rss_html_common.c index 352a3a2..e383117 100644 --- a/src/rss_html_common.c +++ b/src/rss_html_common.c @@ -162,8 +162,12 @@ static struct json_array_element_s* get_last_element_in_json_array(struct json_a } /* TODO: If this fails in the middle, recover and update the next time somehow */ -int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, DownloadItemsData **download_items, char **filenames, int num_download_items) { +int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, DownloadItemsData **download_items, char **filenames, long *timestamps, int num_download_items) { + if(num_download_items == 0) + return 0; + assert(num_download_items <= MAX_UPDATE_ITEMS); + assert(timestamps); int tracked_dir_len = strlen(tracked_dir); int result = 0; @@ -172,7 +176,7 @@ int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, Dow char updated[32]; assert(sizeof(time_t) == sizeof(long)); - sprintf(updated, "%ld", time(NULL)); + sprintf(updated, "%ld", timestamps[num_download_items - 1]); int updated_len = strlen(updated); result = file_overwrite_in_dir(item_filepath, "updated", updated, updated_len); if(result != 0) { @@ -260,6 +264,8 @@ int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, Dow init_json_value_str(&filename_json_value[i], &filename_json_value_str[i]); } + sprintf(updated, "%ld", timestamps[i]); + int updated_len = strlen(updated); create_json_string(&time_value_str[i], updated, updated_len); init_json_value_str(&time_json_value[i], &time_value_str[i]); diff --git a/src/rss_html_common.h b/src/rss_html_common.h index 3ae9d77..2f9e053 100644 --- a/src/rss_html_common.h +++ b/src/rss_html_common.h @@ -28,7 +28,7 @@ int write_plugin_json_to_file(const char *dir, const char *filename, const char Note: tracked_item.json_data becomes invalid after this call. @tracked_dir is also modified and then restored at the end. */ -int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, DownloadItemsData **download_items, char **filenames, int num_download_items); +int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, DownloadItemsData **download_items, char **filenames, long *timestamps, int num_download_items); struct json_value_s* json_object_get_field_by_name(struct json_object_s *json_obj, const char *name); void create_json_string(struct json_string_s *json_result, const char *str, int len); void init_json_value_str(struct json_value_s *json_value, struct json_string_s *json_str); diff --git a/src/transmission.c b/src/transmission.c index 39b355f..9596be0 100644 --- a/src/transmission.c +++ b/src/transmission.c @@ -10,8 +10,6 @@ /* TODO: Make port configurable */ -#define NUM_COLUMNS 10 - int transmission_connect(TransmissionSession *session) { int result = 0; Buffer buffer; |