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é GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
f95a63a3
Valider
f95a63a3
rédigé
Il y a 5 ans
par
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
update_file_legacy
parent
b41c6a5c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion
!6
Resolve "Liste des commandes"
,
!2
update db
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
player/db/update.c
+147
-16
147 ajouts, 16 suppressions
player/db/update.c
avec
147 ajouts
et
16 suppressions
player/db/update.c
+
147
−
16
Voir le fichier @
f95a63a3
...
@@ -5,8 +5,22 @@
...
@@ -5,8 +5,22 @@
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
#include
<sys/stat.h>
#define SQL_LAST_UPDATE "SELECT last_update FROM misc;"
static
const
char
SQL_LAST_UPDATE
[]
=
"SELECT last_update FROM misc;"
;
static
const
char
SQL_INSERT_OLD_KARA
[]
=
"INSERT INTO "
"kara (song_name, source_name, category, language, file_path, is_new) "
"VALUES (?, ?, ?, ?, ?, 0)"
;
static
const
char
SQL_INSERT_NEW_KARA
[]
=
"INSERT INTO "
"kara (song_name, source_name, category, language, file_path,"
" is_new, author_name) "
"VALUES (?, ?, ?, ?, ?, 1, ?)"
;
static
void
convert_legacy_category_type
(
const
char
*
category
,
size_t
category_len
,
const
char
*
type
,
size_t
type_len
);
static
void
static
void
serror
(
sqlite3
*
db
,
const
char
*
msg
)
serror
(
sqlite3
*
db
,
const
char
*
msg
)
...
@@ -23,24 +37,131 @@ mallocf(size_t n)
...
@@ -23,24 +37,131 @@ mallocf(size_t n)
return
res
;
return
res
;
}
}
static
inline
void
*
reallocf
(
void
*
ptr
,
size_t
n
)
{
void
*
res
=
realloc
(
ptr
,
n
);
if
(
!
res
)
fprintf
(
stderr
,
"Failed to allocate %ld bytes.
\n
"
,
n
);
return
res
;
}
static
int
static
int
directories_and_files
(
const
struct
dirent
*
entry
)
directories_and_files
(
const
struct
dirent
*
entry
)
{
{
return
entry
->
d_type
==
DT_REG
||
entry
->
d_type
==
DT_DIR
;
return
(
entry
->
d_type
==
DT_REG
||
entry
->
d_type
==
DT_DIR
)
&&
entry
->
d_name
[
0
]
!=
'.'
;
}
static
void
convert_legacy_category_type
(
const
char
*
category
,
size_t
category_len
,
const
char
*
type
,
size_t
type_len
)
{
// TODO convert category and type -> category and language
}
}
static
int
static
int
update_file
(
sqlite3
*
db
,
const
char
*
filename
,
in
t
last_update
)
update_
legacy_
file
(
sqlite3
*
db
,
const
char
*
filename
,
size_t
prefix
,
time_
t
last_update
)
{
{
// TODO
struct
stat
attrs
;
if
(
stat
(
filename
,
&
attrs
)
<
0
)
return
-
1
;
if
(
attrs
.
st_mtim
.
tv_sec
<
last_update
)
return
0
;
return
0
;
const
char
*
pseudo
=
0
;
size_t
pseudo_len
=
0
;
const
char
*
category
=
0
;
size_t
category_len
=
0
;
const
char
*
name
=
0
;
size_t
name_len
=
0
;
const
char
*
type
=
0
;
size_t
type_len
=
0
;
const
char
*
title
=
0
;
size_t
title_len
=
0
;
const
char
*
file_path
=
filename
+
prefix
;
const
char
*
f
=
file_path
;
category_len
=
strcspn
(
f
,
"/"
);
if
(
!
strncmp
(
f
,
"nouveaux"
,
category_len
))
{
// "Nouveau" kara, in nouveaux/{pseudo}/{category}/...
f
+=
category_len
+
1
;
// Skip "nouveaux/"
pseudo_len
=
strcspn
(
f
,
"/"
);
pseudo
=
f
;
f
+=
pseudo_len
+
1
;
// Skip "{pseudo}/"
category_len
=
strcspn
(
f
,
"/"
);
}
category
=
f
;
f
+=
category_len
+
1
;
// Skip "{category}/"
name_len
=
strcspn
(
f
,
"-"
);
name
=
f
;
f
+=
name_len
+
1
;
type_len
=
strcspn
(
f
,
"-"
);
type
=
f
;
f
+=
type_len
+
1
;
title_len
=
strcspn
(
f
,
"."
);
title
=
f
;
if
(
!
title
)
{
fprintf
(
stderr
,
"Bad file path: '%s'.
\n
"
,
filename
);
return
-
1
;
}
convert_legacy_category_type
(
category
,
category_len
,
type
,
type_len
);
int
status_code
=
-
1
;
sqlite3_stmt
*
stmt
=
0
;
const
char
*
sql
=
pseudo
?
SQL_INSERT_NEW_KARA
:
SQL_INSERT_OLD_KARA
;
if
(
sqlite3_prepare_v2
(
db
,
sql
,
-
1
,
&
stmt
,
0
)
!=
SQLITE_OK
)
{
serror
(
db
,
"Failed to prepare statement"
);
goto
error
;
}
if
(
sqlite3_bind_text
(
stmt
,
0
,
name
,
name_len
,
0
)
!=
SQLITE_OK
)
{
serror
(
"Failed to bind song_name"
);
goto
error
;
}
if
(
sqlite3_bind_text
(
stmt
,
0
,
title
,
title_len
,
0
)
!=
SQLITE_OK
)
{
serror
(
"Failed to bind song_source"
);
goto
error
;
}
if
(
sqlite3_bind_text
(
stmt
,
0
,
category
,
-
1
,
0
)
!=
SQLITE_OK
)
{
serror
(
"Failed to bind category"
);
goto
error
;
}
if
(
sqlite3_bind_text
(
stmt
,
0
,
type
,
-
1
,
0
)
!=
SQLITE_OK
)
{
serror
(
"Failed to bind language"
);
goto
error
;
}
if
(
sqlite3_bind_text
(
stmt
,
0
,
file_path
,
-
1
,
0
)
!=
SQLITE_OK
)
{
serror
(
"Failed to bind file_path"
);
goto
error
;
}
if
(
sqlite3_step
(
stmt
)
!=
SQLITE_DONE
)
{
// TODO handle SQLITE_BUSY (should rollback)
serror
(
"Failed to execute insert statement"
);
goto
error
;
}
status_code
=
0
;
error:
sqlite3_finalize
(
stmt
);
return
status_code
;
}
}
static
int
static
int
update_directory
(
sqlite3
*
db
,
const
char
*
directory
,
in
t
last_update
)
update_directory
(
sqlite3
*
db
,
const
char
*
root
,
time_
t
last_update
)
{
{
int
status_code
=
-
1
;
int
status_code
=
-
1
;
char
**
queue
;
const
size_t
root_len
=
strlen
(
root
)
+
1
;
char
**
queue
=
0
;
size_t
queue_max
=
128
;
size_t
queue_max
=
128
;
size_t
queue_len
=
0
;
size_t
queue_len
=
0
;
...
@@ -48,7 +169,7 @@ update_directory(sqlite3 *db, const char *directory, int last_update)
...
@@ -48,7 +169,7 @@ update_directory(sqlite3 *db, const char *directory, int last_update)
if
(
!
queue
)
if
(
!
queue
)
goto
error
;
goto
error
;
queue
[
0
]
=
strdup
(
directory
);
queue
[
0
]
=
strdup
(
root
);
queue_len
++
;
queue_len
++
;
while
(
queue_len
)
{
while
(
queue_len
)
{
...
@@ -61,18 +182,28 @@ update_directory(sqlite3 *db, const char *directory, int last_update)
...
@@ -61,18 +182,28 @@ update_directory(sqlite3 *db, const char *directory, int last_update)
fprintf
(
stderr
,
"Failed to open '%s': %s.
\n
"
,
dir
,
strerror
(
errno
));
fprintf
(
stderr
,
"Failed to open '%s': %s.
\n
"
,
dir
,
strerror
(
errno
));
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
size_t
dirlen
=
strlen
(
dir
);
size_t
dir_len
=
strlen
(
dir
);
char
*
child
=
mallocf
(
dirlen
+
258
);
// child length (256) + null byte + slash
// child length (256) + null byte + slash
char
*
child
=
mallocf
(
dir_len
+
258
);
if
(
!
child
)
if
(
!
child
)
goto
error
;
goto
error
;
str
cpy
(
child
,
dir
);
mem
cpy
(
child
,
dir
,
dir_len
);
child
[
dirlen
]
=
'/'
;
child
[
dir
_
len
]
=
'/'
;
strcpy
(
child
+
dirlen
+
1
,
children
[
i
]
->
d_name
);
strcpy
(
child
+
dir
_
len
+
1
,
children
[
i
]
->
d_name
);
if
(
children
[
i
]
->
d_type
==
DT_REG
)
{
if
(
children
[
i
]
->
d_type
==
DT_REG
)
{
update_file
(
db
,
child
,
last_update
);
if
(
update_legacy_file
(
db
,
child
,
root_len
,
last_update
)
<
0
)
fprintf
(
stderr
,
"Failed to add '%s'.
\n
"
,
child
);
free
(
child
);
free
(
child
);
}
else
if
(
queue_len
==
queue_max
)
{
queue_max
*=
2
;
char
**
new_queue
=
reallocf
(
queue
,
queue_max
*
sizeof
(
char
*
));
if
(
!
new_queue
)
goto
error
;
queue
=
new_queue
;
queue
[
queue_len
++
]
=
child
;
}
else
{
}
else
{
queue
[
queue_len
++
]
=
child
;
queue
[
queue_len
++
]
=
child
;
}
}
...
@@ -96,7 +227,7 @@ lektor_db_update(sqlite3 *db, const char *directory)
...
@@ -96,7 +227,7 @@ lektor_db_update(sqlite3 *db, const char *directory)
}
}
sqlite3_stmt
*
stmt
=
0
;
sqlite3_stmt
*
stmt
=
0
;
in
t
last_update
=
0
;
time_
t
last_update
=
0
;
if
(
sqlite3_prepare_v2
(
db
,
SQL_LAST_UPDATE
,
-
1
,
&
stmt
,
0
)
!=
SQLITE_OK
)
{
if
(
sqlite3_prepare_v2
(
db
,
SQL_LAST_UPDATE
,
-
1
,
&
stmt
,
0
)
!=
SQLITE_OK
)
{
serror
(
db
,
"Failed to get last update time"
);
serror
(
db
,
"Failed to get last update time"
);
...
@@ -104,7 +235,7 @@ lektor_db_update(sqlite3 *db, const char *directory)
...
@@ -104,7 +235,7 @@ lektor_db_update(sqlite3 *db, const char *directory)
}
}
switch
(
sqlite3_step
(
stmt
))
{
switch
(
sqlite3_step
(
stmt
))
{
case
SQLITE_ROW
:
case
SQLITE_ROW
:
last_update
=
sqlite3_column_int
(
stmt
,
0
);
last_update
=
(
time_t
)
sqlite3_column_int
(
stmt
,
0
);
break
;
break
;
case
SQLITE_DONE
:
case
SQLITE_DONE
:
fprintf
(
stderr
,
"Failed to get last update time: table misc is empty"
);
fprintf
(
stderr
,
"Failed to get last update time: table misc is empty"
);
...
...
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