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

REPO: Force download if the kara if unavlailable

If a kara is present on disk but is marked as unavailable it would not
be downloaded. This commit fix it, if a kara is marked as unavailable it
will be downloaded anyway (may be filtered by user URI...)
parent ef1266ef
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!185REPO: Force download if the kara if unavlailable
...@@ -73,6 +73,7 @@ bool database_get_kara_mtime_path (lkt_db *db, char filepath[PATH_MAX], uint64 ...@@ -73,6 +73,7 @@ bool database_get_kara_mtime_path (lkt_db *db, char filepath[PATH_MAX], uint64
bool database_get_kara_duration_path(lkt_db *db, char filepath[PATH_MAX], uint64_t *duration); bool database_get_kara_duration_path(lkt_db *db, char filepath[PATH_MAX], uint64_t *duration);
bool database_is_kara_mkv (lkt_db *db, char filepath[PATH_MAX], bool *valid_mkv); bool database_is_kara_mkv (lkt_db *db, char filepath[PATH_MAX], bool *valid_mkv);
bool database_is_kara_like (lkt_db *db, int id, const char *str); bool database_is_kara_like (lkt_db *db, int id, const char *str);
bool database_is_kara_available (lkt_db *db, int id, bool *avail);
void database_cache_kara (lkt_db *db, int id); void database_cache_kara (lkt_db *db, int id);
void database_cache_kara_magic (lkt_db *db, int id); void database_cache_kara_magic (lkt_db *db, int id);
......
...@@ -103,6 +103,27 @@ error: ...@@ -103,6 +103,27 @@ error:
return ret_code; return ret_code;
} }
bool
database_is_kara_available(lkt_db *db, int id, bool *avail)
{
sqlite3_stmt *stmt = NULL;
static const char *SQL = "SELECT available FROM kara where id = ?;";
SQLITE_PREPARE(db, stmt, SQL, error);
SQLITE_BIND_INT(db, stmt, 1, id, error);
SQLITE_STEP_ROW(db, stmt, error);
if (avail != NULL)
*avail = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
return true;
error:
if (stmt)
sqlite3_finalize(stmt);
return false;
}
bool bool
database_is_kara_like(lkt_db *db, int id, const char *str) database_is_kara_like(lkt_db *db, int id, const char *str)
{ {
......
...@@ -341,9 +341,10 @@ err: ...@@ -341,9 +341,10 @@ err:
} }
PRIVATE_FUNCTION void PRIVATE_FUNCTION void
___handle_got_json_dl(struct kara *kara, int current_id) ___handle_got_json_dl(struct kara *kara)
{ {
/* Download the kara */ /* Download the kara */
int current_id;
database_queue_current_kara(kara->db, NULL, &current_id); database_queue_current_kara(kara->db, NULL, &current_id);
if (current_id == (int)kara->id) { if (current_id == (int)kara->id) {
LOG_WARN("REPO", "Update currently playing kara %d, skip it", current_id); LOG_WARN("REPO", "Update currently playing kara %d, skip it", current_id);
...@@ -470,9 +471,9 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp, ...@@ -470,9 +471,9 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp,
/* The `void *user` is complete */ /* The `void *user` is complete */
else if (comp) { else if (comp) {
uint64_t filestamp = 0; uint64_t filestamp = 0;
int current_id = 0;
bool magic_valid = 0; bool magic_valid = 0;
unsigned int umask = 0; unsigned int umask = 0;
bool avail = false;
DBCONF_GET_OCTAL(kara->db, "database", "dir_permission", &umask); DBCONF_GET_OCTAL(kara->db, "database", "dir_permission", &umask);
/* Timestamp and presence verification */ /* Timestamp and presence verification */
...@@ -482,6 +483,14 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp, ...@@ -482,6 +483,14 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp,
goto do_it; goto do_it;
} }
if (database_is_kara_available(kara->db, (int)kara->id, &avail) && (!avail)) {
LOG_INFO("REPO",
"Force download of unavailable kara %ld "
"(may still be filtered out)",
kara->id);
goto do_it;
}
database_get_kara_mtime_path(kara->db, kara->filename, &filestamp); database_get_kara_mtime_path(kara->db, kara->filename, &filestamp);
database_is_kara_mkv(kara->db, kara->filename, &magic_valid); database_is_kara_mkv(kara->db, kara->filename, &magic_valid);
if (filestamp == 0 || kara->unix_timestamp != (long)(uint64_t)kara->unix_timestamp || if (filestamp == 0 || kara->unix_timestamp != (long)(uint64_t)kara->unix_timestamp ||
...@@ -503,13 +512,13 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp, ...@@ -503,13 +512,13 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp,
do_it: do_it:
/* Even if we must download the kara, the user could have filtered it out! */ /* Even if we must download the kara, the user could have filtered it out! */
if (lkt_uri_match_kara_metadata(filter, &kara->mdt, kara->db, current_id)) { if (lkt_uri_match_kara_metadata(filter, &kara->mdt, kara->db, (int)kara->id)) {
LOG_DEBUG("REPO", "The kara %d is ignored because it was filtered out", current_id); LOG_DEBUG("REPO", "The kara %ld is ignored because it was filtered out", kara->id);
++(kara->ignored_count); ++(kara->ignored_count);
return 0; return 0;
} }
___handle_got_json_dl(kara, current_id); ___handle_got_json_dl(kara);
lkt_queue_send(kara->repo->queue, LKT_EVENT_DB_UPDATE_TICK, NULL); lkt_queue_send(kara->repo->queue, LKT_EVENT_DB_UPDATE_TICK, NULL);
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter