aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/directory.c13
-rw-r--r--src/song.c17
-rw-r--r--src/tag.c14
3 files changed, 24 insertions, 20 deletions
diff --git a/src/directory.c b/src/directory.c
index 1cd9da9eb..773b16db6 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -723,12 +723,13 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
char buffer[MPD_PATH_MAX * 2];
int bufferSize = MPD_PATH_MAX * 2;
char key[MPD_PATH_MAX * 2];
- Directory *subDirectory;
char *name;
while (myFgets(buffer, bufferSize, fp)
&& prefixcmp(buffer, DIRECTORY_END)) {
if (!prefixcmp(buffer, DIRECTORY_DIR)) {
+ Directory *subdir;
+
strcpy(key, &(buffer[strlen(DIRECTORY_DIR)]));
if (!myFgets(buffer, bufferSize, fp))
FATAL("Error reading db, fgets\n");
@@ -740,9 +741,13 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
if (prefixcmp(buffer, DIRECTORY_BEGIN))
FATAL("Error reading db at line: %s\n", buffer);
name = &(buffer[strlen(DIRECTORY_BEGIN)]);
- subDirectory = newDirectory(name, directory);
- dirvec_add(&directory->children, subDirectory);
- readDirectoryInfo(fp, subDirectory);
+ if ((subdir = getDirectory(name))) {
+ assert(subdir->parent == directory);
+ } else {
+ subdir = newDirectory(name, directory);
+ dirvec_add(&directory->children, subdir);
+ }
+ readDirectoryInfo(fp, subdir);
} else if (!prefixcmp(buffer, SONG_BEGIN)) {
readSongInfoIntoList(fp, directory);
} else {
diff --git a/src/song.c b/src/song.c
index dc100899a..4f7b2f8bb 100644
--- a/src/song.c
+++ b/src/song.c
@@ -123,11 +123,20 @@ static void insertSongIntoList(struct songvec *sv, Song *newsong)
tag_end_add(newsong->tag);
} else { /* prevent dupes, just update the existing song info */
if (existing->mtime != newsong->mtime) {
- tag_free(existing->tag);
- if (newsong->tag)
- tag_end_add(newsong->tag);
- existing->tag = newsong->tag;
existing->mtime = newsong->mtime;
+ if (tag_equal(existing->tag, newsong->tag)) {
+ if (newsong->tag)
+ tag_free(newsong->tag);
+ } else {
+ struct mpd_tag *old_tag = existing->tag;
+
+ if (newsong->tag)
+ tag_end_add(newsong->tag);
+ existing->tag = newsong->tag;
+ if (old_tag)
+ tag_free(old_tag);
+ }
+ /* prevent tag_free in freeJustSong */
newsong->tag = NULL;
}
freeJustSong(newsong);
diff --git a/src/tag.c b/src/tag.c
index 2dcaf4ef8..db446836c 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -296,12 +296,12 @@ void tag_clear_items_by_type(struct mpd_tag *tag, enum tag_type type)
}
}
-static void clearMpdTag(struct mpd_tag *tag)
+void tag_free(struct mpd_tag *tag)
{
int i;
pthread_mutex_lock(&tag_pool_lock);
- for (i = 0; i < tag->numOfItems; i++)
+ for (i = tag->numOfItems; --i >= 0; )
tag_pool_put_item(tag->items[i]);
pthread_mutex_unlock(&tag_pool_lock);
@@ -314,16 +314,6 @@ static void clearMpdTag(struct mpd_tag *tag)
free(tag->items);
}
- tag->items = NULL;
-
- tag->numOfItems = 0;
-
- tag->time = -1;
-}
-
-void tag_free(struct mpd_tag *tag)
-{
- clearMpdTag(tag);
free(tag);
}