aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-08 06:36:40 +0100
committerMax Kellermann <max@duempel.org>2009-01-13 23:09:45 +0100
commit7df1a17db4c2e54ecb0cd3234667289cc0076f08 (patch)
tree29913a265729ec8a49953f988970ce8b806cc60a
parenta0141dbe4f868413d78c94737846279124415479 (diff)
downloadmpd-7df1a17db4c2e54ecb0cd3234667289cc0076f08.tar.gz
mpd-7df1a17db4c2e54ecb0cd3234667289cc0076f08.tar.xz
mpd-7df1a17db4c2e54ecb0cd3234667289cc0076f08.zip
update: save the database even if it is empty
Save an empty database, even if the music directory is empty.
-rw-r--r--NEWS1
-rw-r--r--src/database.h12
-rw-r--r--src/update.c3
3 files changed, 15 insertions, 1 deletions
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 <stdbool.h>
#include <sys/time.h>
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;