From 98c2b7bcdc59a6968d93a25e299c98f0dc7bc1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 2 Sep 2008 21:58:02 +0200 Subject: - Fixed handling of empty tags (in contrast to non-existing ones) --- Makefile | 2 +- src/mfs_subr.c | 17 ++++++++++++----- 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); -- cgit v1.2.3