static enum command_state filescanner_fullrescan(void *arg, int *retval) { DPRINTF(E_LOG, L_SCAN, "Full rescan triggered\n"); player_playback_stop(); db_queue_clear(); inofd_event_unset(); // Clears all inotify watches db_purge_all(); // Clears files, playlists, playlistitems, inotify and groups inofd_event_set(); bulk_scan(F_SCAN_BULK); *retval = 0; return COMMAND_END; }
static void initscan() { time_t starttime; time_t endtime; bool clear_queue_disabled; int i; scanning = true; starttime = time(NULL); listener_notify(LISTENER_UPDATE); // Only clear the queue if enabled (default) in config clear_queue_disabled = cfg_getbool(cfg_getsec(cfg, "mpd"), "clear_queue_on_stop_disable"); if (!clear_queue_disabled) { db_queue_clear(0); } for (i = 0; sources[i]; i++) { if (!sources[i]->disabled && sources[i]->initscan) sources[i]->initscan(); } if (! (cfg_getbool(cfg_getsec(cfg, "library"), "filescan_disable"))) { purge_cruft(starttime); DPRINTF(E_DBG, L_LIB, "Running post library scan jobs\n"); db_hook_post_scan(); } endtime = time(NULL); DPRINTF(E_LOG, L_LIB, "Library init scan completed in %.f sec (%d changes)\n", difftime(endtime, starttime), deferred_update_notifications); scanning = false; if (handle_deferred_update_notifications()) listener_notify(LISTENER_UPDATE | LISTENER_DATABASE); else listener_notify(LISTENER_UPDATE); }
static enum command_state fullrescan(void *arg, int *ret) { time_t starttime; time_t endtime; int i; DPRINTF(E_LOG, L_LIB, "Library full-rescan triggered\n"); listener_notify(LISTENER_UPDATE); starttime = time(NULL); player_playback_stop(); db_queue_clear(0); db_purge_all(); // Clears files, playlists, playlistitems, inotify and groups for (i = 0; sources[i]; i++) { if (!sources[i]->disabled && sources[i]->fullrescan) { DPRINTF(E_INFO, L_LIB, "Full-rescan library source '%s'\n", sources[i]->name); sources[i]->fullrescan(); } else { DPRINTF(E_INFO, L_LIB, "Library source '%s' is disabled\n", sources[i]->name); } } endtime = time(NULL); DPRINTF(E_LOG, L_LIB, "Library full-rescan completed in %.f sec (%d changes)\n", difftime(endtime, starttime), deferred_update_notifications); scanning = false; if (handle_deferred_update_notifications()) listener_notify(LISTENER_UPDATE | LISTENER_DATABASE); else listener_notify(LISTENER_UPDATE); *ret = 0; return COMMAND_END; }
/* Thread: scan */ static void * filescanner(void *arg) { int clear_queue_on_stop_disabled; int ret; #ifdef __linux__ struct sched_param param; /* Lower the priority of the thread so forked-daapd may still respond * during file scan on low power devices. Param must be 0 for the SCHED_BATCH * policy. */ memset(¶m, 0, sizeof(struct sched_param)); ret = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m); if (ret != 0) { DPRINTF(E_LOG, L_SCAN, "Warning: Could not set thread priority to SCHED_BATCH\n"); } #endif ret = db_perthread_init(); if (ret < 0) { DPRINTF(E_LOG, L_SCAN, "Error: DB init failed\n"); pthread_exit(NULL); } ret = db_watch_clear(); if (ret < 0) { DPRINTF(E_LOG, L_SCAN, "Error: could not clear old watches from DB\n"); pthread_exit(NULL); } // Only clear the queue if enabled (default) in config clear_queue_on_stop_disabled = cfg_getbool(cfg_getsec(cfg, "mpd"), "clear_queue_on_stop_disable"); if (!clear_queue_on_stop_disabled) { ret = db_queue_clear(); if (ret < 0) { DPRINTF(E_LOG, L_SCAN, "Error: could not clear queue from DB\n"); pthread_exit(NULL); } } if (cfg_getbool(cfg_getsec(cfg, "library"), "filescan_disable")) bulk_scan(F_SCAN_BULK | F_SCAN_FAST); else bulk_scan(F_SCAN_BULK); if (!scan_exit) { #ifdef HAVE_SPOTIFY_H spotify_login(NULL); #endif /* Enable inotify */ event_add(inoev, NULL); event_base_dispatch(evbase_scan); } if (!scan_exit) DPRINTF(E_FATAL, L_SCAN, "Scan event loop terminated ahead of time!\n"); db_perthread_deinit(); pthread_exit(NULL); }