From 48e757baffbf75bc8a1e4171ad94c27d7356cafa Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 7 May 2021 07:38:59 +0200 Subject: Migrate mangadex to new api, remove .in_progress files in tracked dir if they are old --- src/main.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 7a1e68e..a49acdb 100644 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,8 @@ #include #define NAME_MAX_LEN 250 +/* 30 minutes */ +#define IN_PROGRESS_TIMEOUT_SEC 60L*30L static void usage(void) { fprintf(stderr, "usage: automedia COMMAND\n"); @@ -365,6 +367,8 @@ static void iterate_tracked_items(char *config_dir, IterateTrackedItemCallback i strcat(item_filepath, "/"); int item_filepath_len = strlen(item_filepath); + time_t time_now = time(NULL); + while((dir = readdir(d)) != NULL && automedia_running) { int title_len = strlen(dir->d_name); if((title_len == 1 && dir->d_name[0] == '.') || (title_len == 2 && dir->d_name[0] == '.' && dir->d_name[1] == '.')) @@ -373,9 +377,15 @@ static void iterate_tracked_items(char *config_dir, IterateTrackedItemCallback i strcpy(item_filepath + item_filepath_len, dir->d_name); strcpy(item_filepath + item_filepath_len + title_len, "/.in_progress"); - if(file_exists(item_filepath) == 0) { - fprintf(stderr, "Skipping in-progress rss %s\n", dir->d_name); - continue; + time_t last_modified = 0; + if(file_get_last_modified_time(item_filepath, &last_modified) == 0) { + if(time_now - last_modified > IN_PROGRESS_TIMEOUT_SEC) { + fprintf(stderr, "Removing in-progress item: %s\n", dir->d_name); + remove(item_filepath); + } else { + fprintf(stderr, "Skipping in-progress item: %s\n", dir->d_name); + continue; + } } char *link_file_content = NULL; @@ -577,10 +587,20 @@ static int proc_read_cmdline(const char *pid_str, char *cmdline_data, int cmdlin return 0; } +static int run_mangadex_migration_script() { + const char *args[] = { "/usr/share/automedia/mangadex-upgrade.py", NULL }; + return program_exec(args, NULL, NULL); +} + static void command_sync(int argc, char **argv, char *rss_config_dir, char *html_config_dir, char *program_dir) { if(argc < 1) usage_sync(); + if(run_mangadex_migration_script() != 0) { + fprintf(stderr, "Failed to migrade mangadex manga\n"); + exit(1); + } + char *download_dir = argv[0]; const char automedia_pid_path[] = "/tmp/automedia.pid"; -- cgit v1.2.3