From 9559452124c1d5e7f9fec7dc9cb807b4cef971f1 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sun, 19 Sep 2004 05:18:49 +0000 Subject: [PATCH] Fix date_added, modified problems. Also, fix db_exists --- src/db-gdbm.c | 20 +++++++++++++++----- src/mp3-scanner.c | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/db-gdbm.c b/src/db-gdbm.c index 97fc533e..fa9601b9 100644 --- a/src/db-gdbm.c +++ b/src/db-gdbm.c @@ -768,7 +768,7 @@ int db_add(MP3FILE *pmp3) { ppacked=(MP3PACKED *)pnew->dptr; if(!ppacked->time_added) ppacked->time_added=(int)time(NULL); - ppacked->time_modified=ppacked->time_added; + ppacked->time_modified=(int)time(NULL); ppacked->time_played=0; /* do we want to keep track of this? */ if(gdbm_store(db_songs,dkey,*pnew,GDBM_REPLACE)) { @@ -1192,10 +1192,18 @@ int db_exists(int id) { int *node; int err; MP3FILE *pmp3; + datum key,content; - /* this is wrong and expensive */ + DPRINTF(ERR_DEBUG,"Checking if node %d in db\n"); + key.dptr=(char*)&id; + key.dsize=sizeof(int); - pmp3=db_find(id); + content=gdbm_fetch(db_songs,key); + MEMNOTIFY(content.dptr); + if(!content.dptr) { + DPRINTF(ERR_DEBUG,"Nope! Not in DB\n"); + return 0; + } if(db_update_mode) { /* knock it off the maybe list */ @@ -1205,8 +1213,10 @@ int db_exists(int id) { free(node); } } - - return pmp3 ? 1 : 0; + + free(content.dptr); + DPRINTF(ERR_DEBUG,"Yup, in database\n"); + return 1; } diff --git a/src/mp3-scanner.c b/src/mp3-scanner.c index c7e380fb..bf8dc631 100644 --- a/src/mp3-scanner.c +++ b/src/mp3-scanner.c @@ -376,6 +376,8 @@ int scan_path(char *path) { /* only scan if it's been changed, or empty db */ modified_time=sb.st_mtime; + DPRINTF(ERR_DEBUG,"FS Modified time: %d\n",modified_time); + DPRINTF(ERR_DEBUG,"DB Modified time: %d\n",db_last_modified(sb.st_ino)); if((scan_mode_foreground) || !db_exists(sb.st_ino) || db_last_modified(sb.st_ino) < modified_time) { @@ -490,6 +492,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) { mp3file.time_added=psb->st_mtime; if(psb->st_ctime < mp3file.time_added) mp3file.time_added=psb->st_ctime; + mp3file.time_modified=time(NULL); DPRINTF(ERR_DEBUG," Date Added: %d\n",mp3file.time_added);