summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-09-02 21:58:02 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-09-02 21:58:02 +0200
commit98c2b7bcdc59a6968d93a25e299c98f0dc7bc1bc (patch)
tree4118dfecb0e4e332a9d248a13478fb877b8f2ef8
parent14ae6bb78b79670a33ec9d352d8cb4e8288f582e (diff)
- Fixed handling of empty tags
(in contrast to non-existing ones)
-rw-r--r--Makefile2
-rw-r--r--src/mfs_subr.c17
2 files changed, 13 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 23e9755..d2def1f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CFLAGS = -Wall -std=c99 -D_BSD_SOURCE -I/usr/local/include/ -Iinclude/ \
+CFLAGS = -Wall -std=c99 -D_BSD_SOURCE -I/usr/local/include/ -Iinclude/ -g \
`pkg-config fuse --cflags` `pkg-config taglib --cflags` -DDEBUGGING
LD_ADD = -L/usr/local/lib -lsqlite3 -ltag_c \
diff --git a/src/mfs_subr.c b/src/mfs_subr.c
index b6c5815..0294a06 100644
--- a/src/mfs_subr.c
+++ b/src/mfs_subr.c
@@ -238,6 +238,13 @@ traverse_hierarchy(const char *dirpath, traverse_fn_t fileop)
closedir(dirp);
}
+/* Check if a string is empty (either NULL or "") */
+int
+mfs_empty(const char *str)
+{
+ return (str == NULL || strlen(str) == 0);
+}
+
/* Scan the music initially. */
void
mfs_scan(const char *filepath)
@@ -273,7 +280,7 @@ mfs_scan(const char *filepath)
/* First insert artist if we have it. */
do {
artist = taglib_tag_artist(tag);
- if (artist == NULL)
+ if (mfs_empty(artist))
break;
/* First find out if it exists. */
ret = sqlite3_prepare_v2(handle, "SELECT * FROM artist WHERE "
@@ -310,7 +317,7 @@ mfs_scan(const char *filepath)
/* Insert genre if it doesn't exist. */
do {
genre = taglib_tag_genre(tag);
- if (genre == NULL)
+ if (mfs_empty(genre))
break;
/* First find out if it exists. */
ret = sqlite3_prepare_v2(handle, "SELECT * FROM genre WHERE "
@@ -357,8 +364,8 @@ mfs_scan(const char *filepath)
/* Drop the '.' */
extension++;
- if (title == NULL || genre == NULL || artist == NULL ||
- album == NULL)
+ if (mfs_empty(title) || mfs_empty(genre) || mfs_empty(artist) ||
+ mfs_empty(album))
break;
/* First find out if it exists. */
@@ -400,7 +407,7 @@ mfs_scan(const char *filepath)
if (track) {
asprintf(&trackno, "%02d", track);
- if (trackno == NULL)
+ if (mfs_empty(trackno))
break;
sqlite3_bind_text(st, 6, trackno, -1, SQLITE_TRANSIENT);
free(trackno);