database: db_init() initializes library, does not update
For updating the database, directory_update_init() should be called explicitly.
This commit is contained in:
@@ -22,10 +22,8 @@
|
|||||||
#include "directory_save.h"
|
#include "directory_save.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "ls.h"
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "update.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@@ -48,13 +46,7 @@ static time_t directory_dbModTime;
|
|||||||
void
|
void
|
||||||
db_init(void)
|
db_init(void)
|
||||||
{
|
{
|
||||||
unsigned ret;
|
|
||||||
|
|
||||||
music_root = directory_new("", NULL);
|
music_root = directory_new("", NULL);
|
||||||
|
|
||||||
ret = directory_update_init(NULL);
|
|
||||||
if (ret == 0)
|
|
||||||
g_error("directory update failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -256,6 +248,8 @@ db_load(void)
|
|||||||
int foundFsCharset = 0;
|
int foundFsCharset = 0;
|
||||||
int foundVersion = 0;
|
int foundVersion = 0;
|
||||||
|
|
||||||
|
assert(music_root != NULL);
|
||||||
|
|
||||||
if (!music_root)
|
if (!music_root)
|
||||||
music_root = directory_new("", NULL);
|
music_root = directory_new("", NULL);
|
||||||
while (!(fp = fopen(dbFile, "r")) && errno == EINTR) ;
|
while (!(fp = fopen(dbFile, "r")) && errno == EINTR) ;
|
||||||
|
@@ -24,12 +24,25 @@
|
|||||||
|
|
||||||
struct directory;
|
struct directory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the database library.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
db_init(void);
|
db_init(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_finish(void);
|
db_finish(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the database.
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
db_clear(void)
|
||||||
|
{
|
||||||
|
db_finish();
|
||||||
|
db_init();
|
||||||
|
}
|
||||||
|
|
||||||
struct directory *
|
struct directory *
|
||||||
db_get_root(void);
|
db_get_root(void);
|
||||||
|
|
||||||
|
11
src/main.c
11
src/main.c
@@ -126,7 +126,11 @@ static void changeToUser(void)
|
|||||||
|
|
||||||
static void openDB(Options * options, char *argv0)
|
static void openDB(Options * options, char *argv0)
|
||||||
{
|
{
|
||||||
|
db_init();
|
||||||
|
|
||||||
if (options->createDB > 0 || db_load() < 0) {
|
if (options->createDB > 0 || db_load() < 0) {
|
||||||
|
unsigned job;
|
||||||
|
|
||||||
if (options->createDB < 0) {
|
if (options->createDB < 0) {
|
||||||
g_error("can't open db file and using "
|
g_error("can't open db file and using "
|
||||||
"\"--no-create-db\" command line option; "
|
"\"--no-create-db\" command line option; "
|
||||||
@@ -134,7 +138,12 @@ static void openDB(Options * options, char *argv0)
|
|||||||
}
|
}
|
||||||
if (db_check() < 0)
|
if (db_check() < 0)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
db_init();
|
|
||||||
|
db_clear();
|
||||||
|
|
||||||
|
job = directory_update_init(NULL);
|
||||||
|
if (job == 0)
|
||||||
|
g_error("directory update failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user