aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-07 07:38:59 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-07 07:38:59 +0200
commit48e757baffbf75bc8a1e4171ad94c27d7356cafa (patch)
tree91cad8a939725bd3a52bf2bc726620d164d64a57 /src
parent52c63554190b8421c6f2db72d490f50364a2e23d (diff)
Migrate mangadex to new api, remove .in_progress files in tracked dir if they are old
Diffstat (limited to 'src')
-rw-r--r--src/fileutils.c9
-rw-r--r--src/fileutils.h3
-rw-r--r--src/main.c26
3 files changed, 35 insertions, 3 deletions
diff --git a/src/fileutils.c b/src/fileutils.c
index d7021dc..48cf825 100644
--- a/src/fileutils.c
+++ b/src/fileutils.c
@@ -52,6 +52,15 @@ int file_get_content(const char *filepath, char **data, long *size) {
return result;
}
+int file_get_last_modified_time(const char *path, time_t *last_modified) {
+ struct stat s;
+ if(stat(path, &s) == 0) {
+ *last_modified = s.st_mtim.tv_sec;
+ return 0;
+ }
+ return -1;
+}
+
int create_directory_recursive(char *path) {
int path_len = strlen(path);
char *p = path;
diff --git a/src/fileutils.h b/src/fileutils.h
index 979f656..e243a89 100644
--- a/src/fileutils.h
+++ b/src/fileutils.h
@@ -2,10 +2,13 @@
#define FILEUTILS_H
#include <stddef.h>
+#include <time.h>
const char* get_home_dir();
/* Returns 0 on success */
int file_get_content(const char *filepath, char **data, long *size);
+/* Returns 0 on success */
+int file_get_last_modified_time(const char *path, time_t *last_modified);
/* Returns 0 on success (if the directories are created or if the directories already exists) */
int create_directory_recursive(char *path);
/* Returns 0 on success */
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 <unistd.h>
#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";