* Invalidate the scanner cache when an inotify deletion takes place.

This commit is contained in:
Justin Maggard 2009-04-21 02:50:45 +00:00
parent 6fc880a25d
commit c4ca6527f0
6 changed files with 27 additions and 12 deletions

View File

@ -461,6 +461,8 @@ inotify_remove_file(const char * path)
sqlite_int64 detailID = 0; sqlite_int64 detailID = 0;
int i, rows, children, ret = 1; int i, rows, children, ret = 1;
/* Invalidate the scanner cache so we don't insert files into non-existent containers */
valid_cache = 0;
sql = sqlite3_mprintf("SELECT ID from DETAILS where PATH = '%q'", path); sql = sqlite3_mprintf("SELECT ID from DETAILS where PATH = '%q'", path);
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) ) if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) )
{ {

View File

@ -847,7 +847,7 @@ GetVideoMetadata(const char * path, char * name)
if( !m.mime ) if( !m.mime )
{ {
if( strcmp(ctx->iformat->name, "avi") == 0 ) if( strcmp(ctx->iformat->name, "avi") == 0 )
asprintf(&m.mime, "video/x-msvideo"); asprintf(&m.mime, "video/avi");
else if( strcmp(ctx->iformat->name, "mpegts") == 0 ) else if( strcmp(ctx->iformat->name, "mpegts") == 0 )
asprintf(&m.mime, "video/mpeg"); asprintf(&m.mime, "video/mpeg");
else if( strcmp(ctx->iformat->name, "mpeg") == 0 ) else if( strcmp(ctx->iformat->name, "mpeg") == 0 )

View File

@ -35,6 +35,8 @@
#include "scanner.h" #include "scanner.h"
#include "log.h" #include "log.h"
int valid_cache = 0;
struct virtual_item struct virtual_item
{ {
int objectID; int objectID;
@ -188,7 +190,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
{ {
strcpy(date_taken, "Unknown Date"); strcpy(date_taken, "Unknown Date");
} }
if( strcmp(last_date.name, date_taken) == 0 ) if( valid_cache && strcmp(last_date.name, date_taken) == 0 )
{ {
last_date.objectID++; last_date.objectID++;
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last date item: %s/%s/%X\n", last_date.name, last_date.parentID, last_date.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last date item: %s/%s/%X\n", last_date.name, last_date.parentID, last_date.objectID);
@ -218,14 +220,14 @@ insert_containers(const char * name, const char *path, const char * refID, const
{ {
strcpy(camera, "Unknown Camera"); strcpy(camera, "Unknown Camera");
} }
if( strcmp(camera, last_cam.name) != 0 ) if( !valid_cache || strcmp(camera, last_cam.name) != 0 )
{ {
container = insert_container(camera, "3$13", NULL, "storageFolder", NULL, NULL, NULL, NULL); container = insert_container(camera, "3$13", NULL, "storageFolder", NULL, NULL, NULL, NULL);
sprintf(last_cam.parentID, "3$13$%llX", container>>32); sprintf(last_cam.parentID, "3$13$%llX", container>>32);
strncpy(last_cam.name, camera, 255); strncpy(last_cam.name, camera, 255);
last_camdate.name[0] = '\0'; last_camdate.name[0] = '\0';
} }
if( strcmp(last_camdate.name, date_taken) == 0 ) if( valid_cache && strcmp(last_camdate.name, date_taken) == 0 )
{ {
last_camdate.objectID++; last_camdate.objectID++;
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last camdate item: %s/%s/%s/%X\n", camera, last_camdate.name, last_camdate.parentID, last_camdate.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last camdate item: %s/%s/%s/%X\n", camera, last_camdate.name, last_camdate.parentID, last_camdate.objectID);
@ -283,7 +285,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
if( album ) if( album )
{ {
if( strcmp(album, last_album.name) == 0 ) if( valid_cache && strcmp(album, last_album.name) == 0 )
{ {
last_album.objectID++; last_album.objectID++;
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last album item: %s/%s/%X\n", last_album.name, last_album.parentID, last_album.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last album item: %s/%s/%X\n", last_album.name, last_album.parentID, last_album.objectID);
@ -306,7 +308,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
if( artist ) if( artist )
{ {
if( strcmp(artist, last_artist.name) != 0 ) if( !valid_cache || strcmp(artist, last_artist.name) != 0 )
{ {
container = insert_container(artist, "1$6", NULL, "person.musicArtist", NULL, genre, NULL, NULL); container = insert_container(artist, "1$6", NULL, "person.musicArtist", NULL, genre, NULL, NULL);
sprintf(last_artist.parentID, "1$6$%llX", container>>32); sprintf(last_artist.parentID, "1$6$%llX", container>>32);
@ -321,7 +323,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
{ {
last_artistAlbumAll.objectID++; last_artistAlbumAll.objectID++;
} }
if( strcmp(album?album:"Unknown Album", last_artistAlbum.name) == 0 ) if( valid_cache && strcmp(album?album:"Unknown Album", last_artistAlbum.name) == 0 )
{ {
last_artistAlbum.objectID++; last_artistAlbum.objectID++;
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last artist/album item: %s/%s/%X\n", last_artist.name, last_artist.parentID, last_artist.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Using last artist/album item: %s/%s/%X\n", last_artist.name, last_artist.parentID, last_artist.objectID);
@ -351,7 +353,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
if( genre ) if( genre )
{ {
if( strcmp(genre, last_genre.name) != 0 ) if( !valid_cache || strcmp(genre, last_genre.name) != 0 )
{ {
container = insert_container(genre, "1$5", NULL, "genre.musicGenre", NULL, NULL, NULL, NULL); container = insert_container(genre, "1$5", NULL, "genre.musicGenre", NULL, NULL, NULL, NULL);
sprintf(last_genre.parentID, "1$5$%llX", container>>32); sprintf(last_genre.parentID, "1$5$%llX", container>>32);
@ -366,7 +368,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
{ {
last_genreArtistAll.objectID++; last_genreArtistAll.objectID++;
} }
if( strcmp(artist?artist:"Unknown Artist", last_genreArtist.name) == 0 ) if( valid_cache && strcmp(artist?artist:"Unknown Artist", last_genreArtist.name) == 0 )
{ {
last_genreArtist.objectID++; last_genreArtist.objectID++;
} }
@ -429,6 +431,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
return; return;
} }
sqlite3_free_table(result); sqlite3_free_table(result);
valid_cache = 1;
} }
int int

View File

@ -15,6 +15,8 @@
#define VIDEO_DIR_ID "2$15" #define VIDEO_DIR_ID "2$15"
#define IMAGE_DIR_ID "3$16" #define IMAGE_DIR_ID "3$16"
extern int valid_cache;
int int
is_video(const char * file); is_video(const char * file);

View File

@ -214,6 +214,10 @@ intervening space) by either an integer or the keyword "infinite". */
{ {
h->reqflags |= FLAG_TIMESEEK; h->reqflags |= FLAG_TIMESEEK;
} }
else if(strncasecmp(line, "PlaySpeed.dlna.org", 18)==0)
{
h->reqflags |= FLAG_PLAYSPEED;
}
else if(strncasecmp(line, "realTimeInfo.dlna.org", 21)==0) else if(strncasecmp(line, "realTimeInfo.dlna.org", 21)==0)
{ {
h->reqflags |= FLAG_REALTIMEINFO; h->reqflags |= FLAG_REALTIMEINFO;
@ -556,9 +560,10 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h)
DPRINTF(E_WARN, L_HTTP, "Invalid request, responding ERROR 400. (No Host specified in HTTP headers?)\n"); DPRINTF(E_WARN, L_HTTP, "Invalid request, responding ERROR 400. (No Host specified in HTTP headers?)\n");
Send400(h); Send400(h);
} }
else if( h->reqflags & FLAG_TIMESEEK ) else if( (h->reqflags & FLAG_TIMESEEK) || (h->reqflags & FLAG_PLAYSPEED) )
{ {
DPRINTF(E_WARN, L_HTTP, "DLNA TimeSeek requested, responding ERROR 406\n"); DPRINTF(E_WARN, L_HTTP, "DLNA %s requested, responding ERROR 406\n",
h->reqflags&FLAG_TIMESEEK ? "TimeSeek" : "PlaySpeed");
Send406(h); Send406(h);
} }
else if(strcmp("GET", HttpCommand) == 0) else if(strcmp("GET", HttpCommand) == 0)
@ -1353,7 +1358,7 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
goto error; goto error;
} }
} }
if( h->reqflags & FLAG_XFERINTERACTIVE ) else if( h->reqflags & FLAG_XFERINTERACTIVE )
{ {
if( h->reqflags & FLAG_REALTIMEINFO ) if( h->reqflags & FLAG_REALTIMEINFO )
{ {
@ -1361,12 +1366,14 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
Send400(h); Send400(h);
goto error; goto error;
} }
#if 1 // Some Samsung TVs do this?
if( strncmp(last_file.mime, "image", 5) != 0 ) if( strncmp(last_file.mime, "image", 5) != 0 )
{ {
DPRINTF(E_WARN, L_HTTP, "Client tried to specify transferMode as Interactive without an image!\n"); DPRINTF(E_WARN, L_HTTP, "Client tried to specify transferMode as Interactive without an image!\n");
Send406(h); Send406(h);
goto error; goto error;
} }
#endif
} }
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime)); strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));

View File

@ -79,6 +79,7 @@ struct upnphttp {
#define FLAG_CHUNKED 0x0100 #define FLAG_CHUNKED 0x0100
#define FLAG_TIMESEEK 0x0200 #define FLAG_TIMESEEK 0x0200
#define FLAG_REALTIMEINFO 0x0400 #define FLAG_REALTIMEINFO 0x0400
#define FLAG_PLAYSPEED 0x0800
#define FLAG_XFERSTREAMING 0x1000 #define FLAG_XFERSTREAMING 0x1000
#define FLAG_XFERINTERACTIVE 0x2000 #define FLAG_XFERINTERACTIVE 0x2000
#define FLAG_XFERBACKGROUND 0x4000 #define FLAG_XFERBACKGROUND 0x4000