Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 8ef4e31c rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Timestamp check

parent 1d0e182f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!65Resolve "Sync from kurisu"
...@@ -87,8 +87,7 @@ repo_free(struct lkt_repo *const repo) ...@@ -87,8 +87,7 @@ repo_free(struct lkt_repo *const repo)
if (!curl_init) if (!curl_init)
curl_global_cleanup(); curl_global_cleanup();
} }
static inline int
int
safe_json_get_string(struct json_object *jobj, const char *key, char *content, const size_t len) safe_json_get_string(struct json_object *jobj, const char *key, char *content, const size_t len)
{ {
const char *got; const char *got;
...@@ -101,7 +100,7 @@ safe_json_get_string(struct json_object *jobj, const char *key, char *content, c ...@@ -101,7 +100,7 @@ safe_json_get_string(struct json_object *jobj, const char *key, char *content, c
return 0; return 0;
} }
int static inline int
safe_json_get_int32(struct json_object *json, const char *key, int32_t *ret) safe_json_get_int32(struct json_object *json, const char *key, int32_t *ret)
{ {
struct json_object *field; struct json_object *field;
...@@ -112,6 +111,28 @@ safe_json_get_int32(struct json_object *json, const char *key, int32_t *ret) ...@@ -112,6 +111,28 @@ safe_json_get_int32(struct json_object *json, const char *key, int32_t *ret)
return 0; return 0;
} }
static inline long
get_digit_number(long i)
{
int count = 0;
while (i) {
i /= 10;
++count;
}
return count;
}
int
safe_json_get_long(struct json_object *json, const char *key, long *ret)
{
const int len = get_digit_number(LONG_MAX);
char content[len], *endptr, err;
if (safe_json_get_string(json, key, content, len))
return 1;
STRTOL(*ret, content, endptr, err);
return err;
}
int int
repo_get_alljson_sync(struct lkt_repo *const repo, struct json_object **json) repo_get_alljson_sync(struct lkt_repo *const repo, struct json_object **json)
{ {
...@@ -347,6 +368,13 @@ repo_download_id_async(struct lkt_repo *const repo, const size_t id) ...@@ -347,6 +368,13 @@ repo_download_id_async(struct lkt_repo *const repo, const size_t id)
/* Get all the kara, make them unavailable */ /* 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 static inline void
__handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_object *json) __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_object *json)
{ {
...@@ -355,6 +383,7 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_objec ...@@ -355,6 +383,7 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_objec
int32_t integer, err; int32_t integer, err;
struct kara *kara; struct kara *kara;
char url[URL_MAX_LEN]; char url[URL_MAX_LEN];
long stamp, timestamp;
RETURN_UNLESS(len > 0 && json_object_get_array(json), "Json invalid or array empty", NOTHING); RETURN_UNLESS(len > 0 && json_object_get_array(json), "Json invalid or array empty", NOTHING);
LOG_INFO_SCT("REPO", "Starting to process json for repo %s", repo->name); LOG_INFO_SCT("REPO", "Starting to process json for repo %s", repo->name);
...@@ -380,6 +409,14 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_objec ...@@ -380,6 +409,14 @@ __handle_got_json(volatile sqlite3 *db, struct lkt_repo *repo, struct json_objec
kara->filename[PATH_MAX - 1] = 0; kara->filename[PATH_MAX - 1] = 0;
LOG_INFO_SCT("REPO", "Crafted filename is '%s'", kara->filename); LOG_INFO_SCT("REPO", "Crafted filename is '%s'", kara->filename);
if (safe_json_get_long(kara_json, "unix_timestamp", &timestamp))
continue;
stamp = get_mtime(kara->filename);
if (stamp > timestamp) {
LOG_INFO_SCT("REPO", "Ignore kara '%ld', last timestamp was %ld, new is %ld", kara->id, stamp, timestamp);
continue;
}
err |= safe_json_get_string(kara_json, "song_name", kara->mdt.song_name, LEKTOR_TAG_MAX); err |= safe_json_get_string(kara_json, "song_name", kara->mdt.song_name, LEKTOR_TAG_MAX);
err |= safe_json_get_string(kara_json, "source_name", kara->mdt.source_name, LEKTOR_TAG_MAX); err |= safe_json_get_string(kara_json, "source_name", kara->mdt.source_name, LEKTOR_TAG_MAX);
err |= safe_json_get_string(kara_json, "category", kara->mdt.category, LEKTOR_TAG_MAX); err |= safe_json_get_string(kara_json, "category", kara->mdt.category, LEKTOR_TAG_MAX);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter