commit c9682aa045b8f0125d72d0e3842195bb2a956676
parent d8f9ff644b9bd7c5d40e40f60e81d4c822e16e1e
Author: sin <sin@2f30.org>
Date: Sun, 28 Dec 2014 15:44:53 +0000
Only allow one instance of each file to be added to the library
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/library.c b/library.c
@@ -19,6 +19,10 @@ addlibrary(const char *path)
Decoder *d;
Song *s;
+ s = findsong(path);
+ if (s)
+ return NULL;
+
d = matchdecoder(path);
if (!d)
return NULL;
@@ -44,6 +48,20 @@ addlibrary(const char *path)
}
Song *
+findsong(const char *path)
+{
+ Song *s;
+ int i;
+
+ for (i = 0; i < library.nsongs; i++) {
+ s = library.songs[i];
+ if (!strcmp(s->path, path))
+ return s;
+ }
+ return NULL;
+}
+
+Song *
findsongid(int id)
{
Song *s;
diff --git a/sad.h b/sad.h
@@ -75,6 +75,7 @@ void stopsong(Song *);
/* library.c */
Song *addlibrary(const char *);
+Song *findsong(const char *);
Song *findsongid(int);
void dumplibrary(int);
int searchlibrary(int, const char *);