diff --git a/src/db.c b/src/db.c index 9e13dc28..2a73120c 100644 --- a/src/db.c +++ b/src/db.c @@ -1847,7 +1847,7 @@ db_pl_add_item(int plid, int mfid) #undef QADD_TMPL } -static void +void db_pl_clear_items(int id) { #define Q_TMPL "DELETE FROM playlistitems WHERE playlistid = %d;" diff --git a/src/db.h b/src/db.h index ce8e9c4c..ecb5b05b 100644 --- a/src/db.h +++ b/src/db.h @@ -273,6 +273,9 @@ db_pl_add(char *title, char *path, int *id); int db_pl_add_item(int plid, int mfid); +void +db_pl_clear_items(int id); + void db_pl_delete(int id); diff --git a/src/filescanner.c b/src/filescanner.c index 10f00bef..23df6cd0 100644 --- a/src/filescanner.c +++ b/src/filescanner.c @@ -19,8 +19,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* TODO: inotify vs. playlists */ - #ifdef HAVE_CONFIG_H # include #endif @@ -791,10 +789,15 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie ret = db_file_enable_bycookie(ie->cookie, wi->path); if (ret <= 0) - ret = db_pl_enable_bycookie(ie->cookie, wi->path); - - if (ret <= 0) - ie->mask |= IN_CREATE; + { + /* It's not a known media file, so it's either a new file + * or a playlist, known or not. + * We want to scan the new file and we want to rescan the + * playlist to update playlist items (relative items). + */ + ie->mask |= IN_CREATE; + db_pl_enable_bycookie(ie->cookie, wi->path); + } } if (ie->mask & (IN_MODIFY | IN_CREATE | IN_CLOSE_WRITE)) diff --git a/src/filescanner_m3u.c b/src/filescanner_m3u.c index 18b97488..1fa9713e 100644 --- a/src/filescanner_m3u.c +++ b/src/filescanner_m3u.c @@ -75,23 +75,17 @@ scan_m3u_playlist(char *file) if (pli) { - if (pli->db_timestamp >= sb.st_mtime) - { - DPRINTF(E_DBG, L_SCAN, "Playlist up-to-date\n"); + DPRINTF(E_DBG, L_SCAN, "Playlist found, updating\n"); - db_pl_ping(pli->id); + pl_id = pli->id; - free_pli(pli, 0); - return; - } - else - { - DPRINTF(E_DBG, L_SCAN, "Playlist needs update\n"); + free_pli(pli, 0); - db_pl_delete(pli->id); - free_pli(pli, 0); - } + db_pl_ping(pl_id); + db_pl_clear_items(pl_id); } + else + pl_id = 0; fp = fopen(file, "r"); if (!fp) @@ -101,24 +95,29 @@ scan_m3u_playlist(char *file) return; } - /* Get only the basename, to be used as the playlist name */ - ptr = strrchr(filename, '.'); - if (ptr) - *ptr = '\0'; - - /* Safe: filename is a subset of file which is <= PATH_MAX already */ - strncpy(buf, filename, sizeof(buf)); - - /* Restore the full filename */ - if (ptr) - *ptr = '.'; - - ret = db_pl_add(buf, file, &pl_id); - if (ret < 0) + if (pl_id == 0) { - DPRINTF(E_LOG, L_SCAN, "Error adding m3u playlist '%s'\n", file); + /* Get only the basename, to be used as the playlist name */ + ptr = strrchr(filename, '.'); + if (ptr) + *ptr = '\0'; - return; + /* Safe: filename is a subset of file which is <= PATH_MAX already */ + strncpy(buf, filename, sizeof(buf)); + + /* Restore the full filename */ + if (ptr) + *ptr = '.'; + + ret = db_pl_add(buf, file, &pl_id); + if (ret < 0) + { + DPRINTF(E_LOG, L_SCAN, "Error adding m3u playlist '%s'\n", file); + + return; + } + + DPRINTF(E_INFO, L_SCAN, "Added playlist as id %d\n", pl_id); } ptr = strrchr(file, '/'); @@ -140,8 +139,6 @@ scan_m3u_playlist(char *file) return; } - DPRINTF(E_INFO, L_SCAN, "Added playlist as id %d\n", pl_id); - while (fgets(buf, sizeof(buf), fp) != NULL) { len = strlen(buf);