Always rescan and update playlists

This is needed to keep relative playlist items up to date in the
database when the playlist file moves around.
This commit is contained in:
Julien BLACHE 2009-06-11 19:04:21 +02:00
parent c589d92b14
commit 538d81b402
4 changed files with 41 additions and 38 deletions

View File

@ -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;"

View File

@ -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);

View File

@ -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 <config.h>
#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))

View File

@ -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);