Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
821d73d2
Vérifiée
Valider
821d73d2
rédigé
4 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
MODULE: Differentiate different types of downloads
parent
a27962ea
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!122
Resolve "Import the "Favoris" from kurisu"
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/module/module_repo.c
+56
-54
56 ajouts, 54 suppressions
src/module/module_repo.c
avec
56 ajouts
et
54 suppressions
src/module/module_repo.c
+
56
−
54
Voir le fichier @
821d73d2
...
@@ -20,15 +20,59 @@
...
@@ -20,15 +20,59 @@
#include
<time.h>
#include
<time.h>
#include
<stdarg.h>
#include
<stdarg.h>
/* Different kinds of updates */
#define REPO_UPDATE_KARA (1 << 1)
/* Downloading or rescanning the bakabase */
#define REPO_UPDATE_FAV (1 << 2)
/* Downloading the favorites */
#define REPO_UPDATE_TYPE_COUNT 2
/* Different kinds of download, for some sizes... */
/***********
/***********
* Globals *
* Globals *
***********/
***********/
static
volatile
unsigned
int
__curl_init
=
false
;
static
volatile
unsigned
int
__curl_init
=
false
;
/******************************************************
/*********************
* Private functions needed for the private structure *
* Private structure *
******************************************************/
*********************/
struct
module_repo_internal
{
/* Just the repo */
char
*
name
;
char
*
base_url
;
char
*
kara_dir
;
char
*
get_all_json
;
char
*
get_id_json
;
char
*
get_id_file
;
const
uint64_t
version
;
/* Worker threads */
struct
worker_pool
workers
;
volatile
int
updating
:
REPO_UPDATE_TYPE_COUNT
;
/* The database and the queue */
struct
queue
*
queue
;
volatile
sqlite3
*
db
;
/* Craft a filename for newly downloaded karas. Arguments:
* - str: the destination string, the prefix, i.e. the kara_dir, is already here
* - len: the length of the string, not its size (which is PATH_MAX)
* - kara: the kara structure, which contains all the data to create the filename */
void
(
*
craft_filename
)(
char
str
[
PATH_MAX
],
size_t
,
struct
kara
*
);
};
struct
__memory
{
void
*
mem
;
size_t
size
;
};
struct
__file
{
const
char
*
path
;
int
fd
;
};
/*********************
* Private functions *
*********************/
/* Recursive mkdir, where the last word of the string is a file, not a folder. */
/* Recursive mkdir, where the last word of the string is a file, not a folder. */
static
inline
void
static
inline
void
...
@@ -74,49 +118,6 @@ __craft_filename_non_obfuscate(char str[PATH_MAX], size_t len, struct kara *kara
...
@@ -74,49 +118,6 @@ __craft_filename_non_obfuscate(char str[PATH_MAX], size_t len, struct kara *kara
kara
->
mdt
.
song_type
,
kara
->
mdt
.
song_number
,
kara
->
mdt
.
song_name
);
kara
->
mdt
.
song_type
,
kara
->
mdt
.
song_number
,
kara
->
mdt
.
song_name
);
}
}
/*********************
* Private structure *
*********************/
struct
module_repo_internal
{
/* Just the repo */
char
*
name
;
char
*
base_url
;
char
*
kara_dir
;
char
*
get_all_json
;
char
*
get_id_json
;
char
*
get_id_file
;
const
uint64_t
version
;
/* Worker threads */
struct
worker_pool
workers
;
volatile
int
updating
;
/* The database and the queue */
struct
queue
*
queue
;
volatile
sqlite3
*
db
;
/* Craft a filename for newly downloaded karas. Arguments:
* - str: the destination string, the prefix, i.e. the kara_dir, is already here
* - len: the length of the string, not its size (which is PATH_MAX)
* - kara: the kara structure, which contains all the data to create the filename */
void
(
*
craft_filename
)(
char
str
[
PATH_MAX
],
size_t
,
struct
kara
*
);
};
struct
__memory
{
void
*
mem
;
size_t
size
;
};
struct
__file
{
const
char
*
path
;
int
fd
;
};
/*********************
* Private functions *
*********************/
static
inline
void
static
inline
void
__clean_file
(
struct
__file
*
f
)
__clean_file
(
struct
__file
*
f
)
{
{
...
@@ -426,7 +427,7 @@ __worker_update(void *__repo)
...
@@ -426,7 +427,7 @@ __worker_update(void *__repo)
{
{
struct
module_repo_internal
*
repo
=
__repo
;
struct
module_repo_internal
*
repo
=
__repo
;
lkt_queue_send
(
repo
->
queue
,
lkt_event_db_updating
,
LKT_DB_UPDATING_PROGRESS
);
lkt_queue_send
(
repo
->
queue
,
lkt_event_db_updating
,
LKT_DB_UPDATING_PROGRESS
);
repo
->
updating
=
1
;
repo
->
updating
&
=
REPO_UPDATE_KARA
;
struct
json_object
*
json
;
struct
json_object
*
json
;
LOG_INFO
(
"REPO"
,
"Download kara list from %s (%s), directory is %s"
,
LOG_INFO
(
"REPO"
,
"Download kara list from %s (%s), directory is %s"
,
...
@@ -456,10 +457,10 @@ __worker_rescan(void *__repo)
...
@@ -456,10 +457,10 @@ __worker_rescan(void *__repo)
LOG_ERROR
(
"REPO"
,
"Failed to get kara prefix from config"
);
LOG_ERROR
(
"REPO"
,
"Failed to get kara prefix from config"
);
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
}
}
repo
->
updating
=
1
;
repo
->
updating
&
=
REPO_UPDATE_KARA
;
database_update
(
repo
->
db
,
kara_prefix
,
0
);
/* Don't check timestamp.
database_update
(
repo
->
db
,
kara_prefix
,
0
);
/* Don't check timestamp.
TODO: Sometimes we want to check them */
*
TODO: Sometimes we want to check them */
repo
->
updating
=
0
;
repo
->
updating
&
=
(
~
REPO_UPDATE_KARA
)
;
lkt_queue_send
(
repo
->
queue
,
lkt_event_db_updating
,
LKT_DB_UPDATING_FINISHED
);
lkt_queue_send
(
repo
->
queue
,
lkt_event_db_updating
,
LKT_DB_UPDATING_FINISHED
);
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
}
}
...
@@ -646,12 +647,12 @@ mod_update(va_list *va)
...
@@ -646,12 +647,12 @@ mod_update(va_list *va)
va_copy
(
copy
,
*
va
);
va_copy
(
copy
,
*
va
);
repo
=
(
struct
module_repo_internal
**
)
va_arg
(
copy
,
void
**
);
repo
=
(
struct
module_repo_internal
**
)
va_arg
(
copy
,
void
**
);
if
((
*
repo
)
->
updating
)
{
if
((
*
repo
)
->
updating
&
REPO_UPDATE_KARA
)
{
LOG_WARN
(
"REPO"
,
"Already updating"
);
LOG_WARN
(
"REPO"
,
"Already updating"
);
va_end
(
copy
);
va_end
(
copy
);
return
0
;
return
0
;
}
}
(
*
repo
)
->
updating
=
1
;
(
*
repo
)
->
updating
&
=
REPO_UPDATE_KARA
;
if
(
worker_pool_push
(
&
(
*
repo
)
->
workers
,
__worker_update
,
(
void
*
)
*
repo
))
{
if
(
worker_pool_push
(
&
(
*
repo
)
->
workers
,
__worker_update
,
(
void
*
)
*
repo
))
{
LOG_ERROR
(
"REPO"
,
"Out of memory"
);
LOG_ERROR
(
"REPO"
,
"Out of memory"
);
va_end
(
copy
);
va_end
(
copy
);
...
@@ -671,12 +672,12 @@ mod_rescan(va_list *va)
...
@@ -671,12 +672,12 @@ mod_rescan(va_list *va)
va_copy
(
copy
,
*
va
);
va_copy
(
copy
,
*
va
);
repo
=
(
struct
module_repo_internal
**
)
va_arg
(
copy
,
void
**
);
repo
=
(
struct
module_repo_internal
**
)
va_arg
(
copy
,
void
**
);
if
((
*
repo
)
->
updating
)
{
if
((
*
repo
)
->
updating
&
REPO_UPDATE_KARA
)
{
LOG_WARN
(
"REPO"
,
"Already updating"
);
LOG_WARN
(
"REPO"
,
"Already updating"
);
va_end
(
copy
);
va_end
(
copy
);
return
0
;
return
0
;
}
}
(
*
repo
)
->
updating
=
1
;
(
*
repo
)
->
updating
&
=
REPO_UPDATE_KARA
;
if
(
worker_pool_push
(
&
(
*
repo
)
->
workers
,
__worker_rescan
,
(
void
*
)
*
repo
))
{
if
(
worker_pool_push
(
&
(
*
repo
)
->
workers
,
__worker_rescan
,
(
void
*
)
*
repo
))
{
LOG_ERROR
(
"REPO"
,
"Out of memory"
);
LOG_ERROR
(
"REPO"
,
"Out of memory"
);
va_end
(
copy
);
va_end
(
copy
);
...
@@ -699,6 +700,7 @@ mod_is_updating(va_list *va)
...
@@ -699,6 +700,7 @@ mod_is_updating(va_list *va)
ret
=
va_arg
(
copy
,
int
*
);
ret
=
va_arg
(
copy
,
int
*
);
if
(
ret
==
NULL
)
if
(
ret
==
NULL
)
return
1
;
return
1
;
/* Don't differentiate kinds of downloads here */
*
ret
=
(
*
repo
)
->
updating
;
*
ret
=
(
*
repo
)
->
updating
;
va_end
(
copy
);
va_end
(
copy
);
return
0
;
return
0
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter