From 7df1a17db4c2e54ecb0cd3234667289cc0076f08 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 8 Jan 2009 06:36:40 +0100 Subject: update: save the database even if it is empty Save an empty database, even if the music directory is empty. --- NEWS | 1 + src/database.h | 12 ++++++++++++ src/update.c | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e9959c157..93c4d5965 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ MPD 0.14.1 - not yet released - jack: allocate default port names (fixes a crash) * update: - refresh stats after update + - save the database even if it is empty * log: automatically append newline * fix setenv() conflict on Solaris * configure.ac: check for pkg-config before using it diff --git a/src/database.h b/src/database.h index b6884b604..ff17e3eb0 100644 --- a/src/database.h +++ b/src/database.h @@ -20,6 +20,7 @@ #ifndef MPD_DATABASE_H #define MPD_DATABASE_H +#include #include struct directory; @@ -55,4 +56,15 @@ db_load(void); time_t db_get_mtime(void); +/** + * Returns true if there is a valid database file on the disk. + */ +static inline bool +db_exists(void) +{ + /* mtime is set only if the database file was loaded or saved + successfully */ + return db_get_mtime() > 0; +} + #endif diff --git a/src/update.c b/src/update.c index 10108f0a9..58f1b08d1 100644 --- a/src/update.c +++ b/src/update.c @@ -518,8 +518,9 @@ static void * update_task(void *_path) updateDirectory(directory, &st); } - if (modified) + if (modified || !db_exists()) db_save(); + progress = UPDATE_PROGRESS_DONE; wakeup_main_task(); return NULL; -- cgit v1.2.3