scanner: Clean up non-destructive rescan
Fix several issues with the non-destructive rescan functionality. Most of these issues also affected inotify scanning as well. These include annoying debug messages, adding album art for files that we aren't supposed to be scanning anyway, incrementing the UpdateID when no changes were made to the database, and other smaller issues.
This commit is contained in:
126
scanner.c
126
scanner.c
@@ -449,42 +449,45 @@ insert_directory(const char *name, const char *path, const char *base, const cha
|
||||
int
|
||||
insert_file(const char *name, const char *path, const char *parentID, int object, media_types types)
|
||||
{
|
||||
char class[32];
|
||||
const char *class;
|
||||
char objectID[64];
|
||||
int64_t detailID = 0;
|
||||
char base[8];
|
||||
char *typedir_parentID;
|
||||
char *baseid;
|
||||
char *objname;
|
||||
media_types mtype = get_media_type(name);
|
||||
|
||||
if( (types & TYPE_IMAGES) && is_image(name) )
|
||||
if( mtype == TYPE_IMAGE && (types & TYPE_IMAGE) )
|
||||
{
|
||||
if( is_album_art(name) )
|
||||
return -1;
|
||||
strcpy(base, IMAGE_DIR_ID);
|
||||
strcpy(class, "item.imageItem.photo");
|
||||
class = "item.imageItem.photo";
|
||||
detailID = GetImageMetadata(path, name);
|
||||
}
|
||||
else if( (types & TYPE_VIDEO) && is_video(name) )
|
||||
else if( mtype == TYPE_VIDEO && (types & TYPE_VIDEO) )
|
||||
{
|
||||
strcpy(base, VIDEO_DIR_ID);
|
||||
strcpy(class, "item.videoItem");
|
||||
class = "item.videoItem";
|
||||
detailID = GetVideoMetadata(path, name);
|
||||
}
|
||||
else if( is_playlist(name) )
|
||||
else if( mtype == TYPE_PLAYLIST && (types & TYPE_PLAYLIST) )
|
||||
{
|
||||
if( insert_playlist(path, name) == 0 )
|
||||
return 1;
|
||||
}
|
||||
if( !detailID && (types & TYPE_AUDIO) && is_audio(name) )
|
||||
/* Some file extensions can be used for both audio and video.
|
||||
** Fall back to audio on these files if video parsing fails. */
|
||||
if (!detailID && (types & TYPE_AUDIO) && is_audio(name) )
|
||||
{
|
||||
strcpy(base, MUSIC_DIR_ID);
|
||||
strcpy(class, "item.audioItem.musicTrack");
|
||||
class = "item.audioItem.musicTrack";
|
||||
detailID = GetAudioMetadata(path, name);
|
||||
}
|
||||
if( !detailID )
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCANNER, "Unsuccessful getting details for %s!\n", path);
|
||||
DPRINTF(E_WARN, L_SCANNER, "Unsuccessful getting details for %s\n", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -628,9 +631,9 @@ filter_type(scan_filter *d)
|
||||
{
|
||||
#if HAVE_STRUCT_DIRENT_D_TYPE
|
||||
return ( (d->d_type == DT_DIR) ||
|
||||
(d->d_type == DT_LNK) ||
|
||||
(d->d_type == DT_UNKNOWN)
|
||||
);
|
||||
(d->d_type == DT_LNK) ||
|
||||
(d->d_type == DT_UNKNOWN)
|
||||
);
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
@@ -640,79 +643,79 @@ static int
|
||||
filter_a(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
(is_audio(d->d_name) ||
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
}
|
||||
|
||||
static int
|
||||
filter_av(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
(is_audio(d->d_name) ||
|
||||
is_video(d->d_name) ||
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
}
|
||||
|
||||
static int
|
||||
filter_ap(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
(is_audio(d->d_name) ||
|
||||
is_image(d->d_name) ||
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
}
|
||||
|
||||
static int
|
||||
filter_v(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
is_video(d->d_name)))
|
||||
);
|
||||
is_video(d->d_name)))
|
||||
);
|
||||
}
|
||||
|
||||
static int
|
||||
filter_vp(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
(is_video(d->d_name) ||
|
||||
is_image(d->d_name))))
|
||||
);
|
||||
is_image(d->d_name))))
|
||||
);
|
||||
}
|
||||
|
||||
static int
|
||||
filter_p(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
is_image(d->d_name)))
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
static int
|
||||
filter_avp(scan_filter *d)
|
||||
{
|
||||
return ( filter_hidden(d) &&
|
||||
(filter_type(d) ||
|
||||
(filter_type(d) ||
|
||||
(is_reg(d) &&
|
||||
(is_audio(d->d_name) ||
|
||||
is_image(d->d_name) ||
|
||||
is_video(d->d_name) ||
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
is_playlist(d->d_name))))
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -737,16 +740,16 @@ ScanDirectory(const char *dir, const char *parent, media_types dir_types)
|
||||
case TYPE_AUDIO|TYPE_VIDEO:
|
||||
n = scandir(dir, &namelist, filter_av, alphasort);
|
||||
break;
|
||||
case TYPE_AUDIO|TYPE_IMAGES:
|
||||
case TYPE_AUDIO|TYPE_IMAGE:
|
||||
n = scandir(dir, &namelist, filter_ap, alphasort);
|
||||
break;
|
||||
case TYPE_VIDEO:
|
||||
n = scandir(dir, &namelist, filter_v, alphasort);
|
||||
break;
|
||||
case TYPE_VIDEO|TYPE_IMAGES:
|
||||
case TYPE_VIDEO|TYPE_IMAGE:
|
||||
n = scandir(dir, &namelist, filter_vp, alphasort);
|
||||
break;
|
||||
case TYPE_IMAGES:
|
||||
case TYPE_IMAGE:
|
||||
n = scandir(dir, &namelist, filter_p, alphasort);
|
||||
break;
|
||||
default:
|
||||
@@ -818,26 +821,6 @@ ScanDirectory(const char *dir, const char *parent, media_types dir_types)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_notify_start(void)
|
||||
{
|
||||
#ifdef READYNAS
|
||||
FILE *flag = fopen("/ramfs/.upnp-av_scan", "w");
|
||||
if( flag )
|
||||
fclose(flag);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
_notify_stop(void)
|
||||
{
|
||||
#ifdef READYNAS
|
||||
if( access("/ramfs/.rescan_done", F_OK) == 0 )
|
||||
system("/bin/sh /ramfs/.rescan_done");
|
||||
unlink("/ramfs/.upnp-av_scan");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* rescan functions added by shrimpkin@sourceforge.net */
|
||||
static int
|
||||
cb_orphans(void *args, int argc, char **argv, char **azColName)
|
||||
@@ -866,6 +849,8 @@ start_rescan(void)
|
||||
char *zErrMsg;
|
||||
const char *sql_files = "SELECT path, mime FROM details WHERE path NOT NULL AND mime IS NOT NULL;";
|
||||
const char *sql_dir = "SELECT path, mime FROM details WHERE path NOT NULL AND mime IS NULL;";
|
||||
int changes = sqlite3_total_changes(db);
|
||||
const char *summary;
|
||||
int ret;
|
||||
|
||||
DPRINTF(E_INFO, L_SCANNER, "Starting rescan\n");
|
||||
@@ -896,12 +881,18 @@ start_rescan(void)
|
||||
monitor_insert_directory(0, esc_name, path);
|
||||
free(esc_name);
|
||||
}
|
||||
DPRINTF(E_INFO, L_SCANNER, "Rescan completed\n");
|
||||
fill_playlists();
|
||||
|
||||
if (sqlite3_total_changes(db) != changes)
|
||||
summary = "changes found";
|
||||
else
|
||||
summary = "no changes";
|
||||
DPRINTF(E_INFO, L_SCANNER, "Rescan completed. (%s)\n", summary);
|
||||
}
|
||||
/* end rescan functions */
|
||||
|
||||
void
|
||||
start_scanner()
|
||||
start_scanner(void)
|
||||
{
|
||||
struct media_dir_s *media_path;
|
||||
char path[MAXPATHLEN];
|
||||
@@ -910,15 +901,12 @@ start_scanner()
|
||||
DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread priority\n");
|
||||
|
||||
setlocale(LC_COLLATE, "");
|
||||
|
||||
av_register_all();
|
||||
av_log_set_level(AV_LOG_PANIC);
|
||||
if( rescan_db )
|
||||
{
|
||||
start_rescan();
|
||||
return;
|
||||
}
|
||||
_notify_start();
|
||||
|
||||
if( GETFLAG(RESCAN_MASK) )
|
||||
return start_rescan();
|
||||
|
||||
for( media_path = media_dirs; media_path != NULL; media_path = media_path->next )
|
||||
{
|
||||
int64_t id;
|
||||
@@ -941,20 +929,12 @@ start_scanner()
|
||||
ScanDirectory(media_path->path, parent, media_path->types);
|
||||
sql_exec(db, "INSERT into SETTINGS values (%Q, %Q)", "media_dir", media_path->path);
|
||||
}
|
||||
_notify_stop();
|
||||
/* Create this index after scanning, so it doesn't slow down the scanning process.
|
||||
* This index is very useful for large libraries used with an XBox360 (or any
|
||||
* client that uses UPnPSearch on large containers). */
|
||||
sql_exec(db, "create INDEX IDX_SEARCH_OPT ON OBJECTS(OBJECT_ID, CLASS, DETAIL_ID);");
|
||||
|
||||
if( GETFLAG(NO_PLAYLIST_MASK) )
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCANNER, "Playlist creation disabled\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fill_playlists();
|
||||
}
|
||||
fill_playlists();
|
||||
|
||||
DPRINTF(E_DEBUG, L_SCANNER, "Initial file scan completed\n");
|
||||
//JM: Set up a db version number, so we know if we need to rebuild due to a new structure.
|
||||
|
||||
Reference in New Issue
Block a user