From 72191db7e77cd26502554a7ba066722c004e60ff Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 30 Apr 2020 21:18:52 +0200
Subject: [PATCH] Cleaning unused code

---
 inc/common/common.h  |  2 +-
 inc/lektor/net.h     | 15 ++-----------
 meson.build          |  1 -
 src/commands.c       |  2 +-
 src/common.c         |  8 ++++---
 src/net/downloader.c | 50 ++++----------------------------------------
 src/net/sync.c       | 11 ----------
 7 files changed, 13 insertions(+), 76 deletions(-)
 delete mode 100644 src/net/sync.c

diff --git a/inc/common/common.h b/inc/common/common.h
index b56af85e..010317a5 100644
--- a/inc/common/common.h
+++ b/inc/common/common.h
@@ -9,4 +9,4 @@ extern void __not_implemented(const char *func, char *file, int line);
 #define UNUSED(...) __unused((void *) __VA_ARGS__)
 void __unused(void *, ...);
 
-long min_long(long a, long b);
+long get_mtime(const char *path);
diff --git a/inc/lektor/net.h b/inc/lektor/net.h
index 0c1428a1..f6a7f4af 100644
--- a/inc/lektor/net.h
+++ b/inc/lektor/net.h
@@ -41,20 +41,9 @@ struct lkt_repo {
 int  repo_new (struct lkt_repo *const repo, const char *name, const char *url, volatile sqlite3 *db);
 void repo_free(struct lkt_repo *const repo);
 
-/* Get metadata of a kara. */
 int repo_get_id          (struct lkt_repo *const repo, const uint64_t id, struct kara_metadata *mdt);
-int repo_get_alljson_sync(struct lkt_repo *const repo, struct json_object **json);
-int repo_get_allid_async (struct lkt_repo *const repo);
-
-/* Download a kara. */
-int repo_download_id_sync (struct lkt_repo *const repo, const uint64_t id, const char *kara_path, struct kara_metadata *mdt);
-int repo_download_id_async(struct lkt_repo *const repo, const size_t id);
-
-/* Scan and update the DB.
-   If only update from the kurisu repo, rescan must be null, if you want to
-   also scan the directories, set rescan to a non zero value. If the uri is
-   null, will just update/rescan everything. */
-int repo_sync(struct lkt_repo *const repo, struct lkt_uri *uri, int rescan);
+int repo_update          (struct lkt_repo *const repo);
+int repo_download_id_sync(struct lkt_repo *const repo, const uint64_t id, const char *kara_path, struct kara_metadata *mdt);
 
 /* Create and destruct a command structure. */
 struct lkt_command lkt_command_parse(char *raw);
diff --git a/meson.build b/meson.build
index ce0eda12..8e6fea1c 100644
--- a/meson.build
+++ b/meson.build
@@ -57,7 +57,6 @@ core_sources =  [ 'src/mkv/bufferfd.c'
                 , 'src/net/listen.c'
                 , 'src/net/message.c'
                 , 'src/net/downloader.c'
-                , 'src/net/sync.c'
                 , 'src/config.c'
                 , 'src/uri.c'
                 , 'src/ini/ini.c'
diff --git a/src/commands.c b/src/commands.c
index 7189a6cf..d5e1d6a5 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -58,7 +58,7 @@ command_update(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]
     RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false);
     srv->mpd_idle_events |= MPD_IDLE_UPDATE;
     srv->mpd_idle_events |= MPD_IDLE_DATABASE;
-    return ! repo_get_allid_async(&srv->repo);
+    return ! repo_update(&srv->repo);
 }
 
 bool
diff --git a/src/common.c b/src/common.c
index 8bc985b3..6b906e78 100644
--- a/src/common.c
+++ b/src/common.c
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 void
 __not_implemented(const char *func, char *file, int line)
@@ -128,8 +129,9 @@ get_stdin_line(const char *prompt, char *buf, size_t len)
     return is_utf8(buf);
 }
 
-long
-min_long(long a, long b)
+inline long
+get_mtime(const char *path)
 {
-    return a < b ? a : b;
+    struct stat statbuf;
+    return (stat(path, &statbuf) == -1) ? 0 : statbuf.st_mtime;
 }
diff --git a/src/net/downloader.c b/src/net/downloader.c
index 5e18a28d..76a9307a 100644
--- a/src/net/downloader.c
+++ b/src/net/downloader.c
@@ -133,8 +133,8 @@ safe_json_get_long(struct json_object *json, const char *key, long *ret)
     return err;
 }
 
-int
-repo_get_alljson_sync(struct lkt_repo *const repo, struct json_object **json)
+static inline int
+__json_sync(struct lkt_repo *const repo, struct json_object **json)
 {
     RETURN_UNLESS(json, "Invalid argument", 1);
 
@@ -331,50 +331,8 @@ repo_download_id_sync(struct lkt_repo *const repo, const uint64_t id, const char
     return 0;
 }
 
-/* Download a kara */
-
-static inline void *
-__repo_download_id_async(void *arg)
-{
-    struct lkt_repo *const repo = *(struct lkt_repo **) arg;
-    struct kara *kara           = (struct kara *) (((struct lkt_repo **) arg) + 1);
-
-    if (repo_download_id_sync(repo, kara->id, kara->filename, &kara->mdt))
-        LOG_ERROR_SCT("REPO", "Failed to download kara '%ld' with path '%s'", kara->id, kara->filename);
-
-    free(arg);
-    return NULL;
-}
-
-int
-repo_download_id_async(struct lkt_repo *const repo, const size_t id)
-{
-    RETURN_IF(id == 0, "Invalid argument", 1);
-
-    /* Create the argument, I know it's ugly */
-    void *arg = malloc(sizeof(struct kara) + sizeof(struct lkt_repo *));
-    RETURN_UNLESS(arg, "Out of memory", 1);
-    *(struct lkt_repo **) arg = repo;
-    struct kara *kara         = (struct kara *) (((struct lkt_repo **) arg) + 1);
-
-    /* Init arg */
-    snprintf(kara->filename, PATH_MAX - 1, "%s%lu.mkv", repo->kara_dir, id);
-    kara->filename[PATH_MAX - 1] = 0;
-    kara->id = id;
-
-    /* Thread */
-    return mthread_create(NULL, ATTR_DETACHED, __repo_download_id_async, arg);
-}
-
 /* Get all the kara, make them unavailable */
 
-static inline time_t
-get_mtime(const char *path)
-{
-    struct stat statbuf;
-    return (stat(path, &statbuf) == -1) ? 0 : statbuf.st_mtime;
-}
-
 static inline void
 __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_object *json)
 {
@@ -468,7 +426,7 @@ __repo_get_all_id_async(void *arg)
     struct lkt_repo *const repo = arg;
     LOG_INFO_SCT("REPO", "Download kara list from %s (%s), directory is %s",
                  repo->name, repo->base_url, repo->kara_dir);
-    repo_get_alljson_sync(repo, &json);
+    __json_sync(repo, &json);
     __handle_got_json(repo->db, repo, json);
     LOG_INFO_SCT("REPO", "%s", "Finished to download and insert kara list");
     json_object_put(json);
@@ -477,7 +435,7 @@ __repo_get_all_id_async(void *arg)
 }
 
 inline int
-repo_get_allid_async(struct lkt_repo *const repo)
+repo_update(struct lkt_repo *const repo)
 {
     return mthread_create(NULL, ATTR_DETACHED, __repo_get_all_id_async, repo);
 }
diff --git a/src/net/sync.c b/src/net/sync.c
deleted file mode 100644
index 5d952bbf..00000000
--- a/src/net/sync.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#define _POSIX_C_SOURCE 200809L
-
-#include <common/common.h>
-#include <lektor/net.h>
-
-int
-repo_sync(struct lkt_repo *const repo, struct lkt_uri *uri, int rescan)
-{
-    UNUSED(repo, rescan, uri);
-    return 1;
-}
-- 
GitLab