* Fix inotify detection in the root media directory.
* Hold off creating inotify watches until the initial file scan is complete. * Use a thread instead of fork when scanning.
This commit is contained in:
parent
35ce036f3c
commit
14547e2266
15
inotify.c
15
inotify.c
@ -120,6 +120,7 @@ inotify_create_watches(int fd)
|
||||
unsigned int num_watches = 0, watch_limit = 8192;
|
||||
char **result;
|
||||
int i, rows = 0;
|
||||
struct media_dir_s * media_path;
|
||||
|
||||
if( sql_get_table(db, "SELECT count(ID) from DETAILS where SIZE is NULL and PATH is not NULL", &result, &rows, NULL) == SQLITE_OK )
|
||||
{
|
||||
@ -168,6 +169,12 @@ inotify_create_watches(int fd)
|
||||
"Hopefully it is enough to cover %u current directories plus any new ones added.\n", num_watches);
|
||||
}
|
||||
|
||||
media_path = media_dirs;
|
||||
while( media_path )
|
||||
{
|
||||
add_watch(fd, media_path->path);
|
||||
media_path = media_path->next;
|
||||
}
|
||||
sql_get_table(db, "SELECT PATH from DETAILS where SIZE is NULL and PATH is not NULL", &result, &rows, NULL);
|
||||
for( i=1; i <= rows; i++ )
|
||||
{
|
||||
@ -310,7 +317,8 @@ inotify_insert_file(char * name, const char * path)
|
||||
|
||||
if( strcmp(parent_buf, "/") == 0 )
|
||||
{
|
||||
printf("No parents found!\n");
|
||||
id = strdup("");
|
||||
depth = 0;
|
||||
break;
|
||||
}
|
||||
strcpy(path_buf, path);
|
||||
@ -353,6 +361,7 @@ inotify_insert_directory(int fd, char *name, const char * path)
|
||||
else
|
||||
{
|
||||
sqlite3_free_table(result);
|
||||
insert_directory(name, path, BROWSEDIR_ID, "", get_next_available_id("OBJECTS", id));
|
||||
}
|
||||
}
|
||||
free(parent_buf);
|
||||
@ -493,6 +502,10 @@ start_inotify()
|
||||
perror( "inotify_init" );
|
||||
}
|
||||
|
||||
while( scanning )
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
inotify_create_watches(fd);
|
||||
while( 1 )
|
||||
{
|
||||
|
@ -153,6 +153,8 @@ GetAudioMetadata(const char * path, char * name)
|
||||
|
||||
tag = taglib_file_tag(audio_file);
|
||||
properties = taglib_file_audioproperties(audio_file);
|
||||
if( !properties )
|
||||
return 0;
|
||||
|
||||
seconds = taglib_audioproperties_length(properties) % 60;
|
||||
minutes = (taglib_audioproperties_length(properties) - seconds) / 60;
|
||||
|
26
minidlna.c
26
minidlna.c
@ -600,7 +600,7 @@ main(int argc, char * * argv)
|
||||
int max_fd = -1;
|
||||
int last_changecnt = 0;
|
||||
char * sql;
|
||||
pthread_t thread;
|
||||
pthread_t thread[2];
|
||||
|
||||
if(init(argc, argv) != 0)
|
||||
return 1;
|
||||
@ -622,48 +622,34 @@ main(int argc, char * * argv)
|
||||
{
|
||||
char **result;
|
||||
int rows;
|
||||
sqlite3_busy_timeout(db, 2000);
|
||||
sqlite3_busy_timeout(db, 2500);
|
||||
if( sql_get_table(db, "pragma user_version", &result, &rows, 0) == SQLITE_OK )
|
||||
{
|
||||
if( atoi(result[1]) != DB_VERSION ) {
|
||||
struct media_dir_s * media_path = media_dirs;
|
||||
printf("Database version mismatch; need to recreate...\n");
|
||||
sqlite3_close(db);
|
||||
unlink(DB_PATH "/files.db");
|
||||
system("rm -rf " DB_PATH "/art_cache");
|
||||
sqlite3_open(DB_PATH "/files.db", &db);
|
||||
freopen("/dev/null", "a", stderr);
|
||||
if( CreateDatabase() != 0 )
|
||||
{
|
||||
fprintf(stderr, "Error creating database!\n");
|
||||
return -1;
|
||||
}
|
||||
#if USE_FORK
|
||||
pid_t newpid = fork();
|
||||
if( newpid )
|
||||
goto fork_done;
|
||||
#endif
|
||||
while( media_path )
|
||||
if( pthread_create(&thread[0], NULL, start_scanner, NULL) )
|
||||
{
|
||||
ScanDirectory(media_path->path, NULL, media_path->type);
|
||||
media_path = media_path->next;
|
||||
printf("ERROR: pthread_create() failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
freopen("/proc/self/fd/2", "a", stderr);
|
||||
#if USE_FORK
|
||||
_exit(0);
|
||||
#endif
|
||||
}
|
||||
sqlite3_free_table(result);
|
||||
}
|
||||
if( GETFLAG(INOTIFYMASK) && pthread_create(&thread, NULL, start_inotify, NULL) )
|
||||
if( GETFLAG(INOTIFYMASK) && pthread_create(&thread[1], NULL, start_inotify, NULL) )
|
||||
{
|
||||
printf("ERROR: pthread_create() failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
#if USE_FORK
|
||||
fork_done:
|
||||
#endif
|
||||
|
||||
sudp = OpenAndConfSSDPReceiveSocket(n_lan_addr, lan_addr);
|
||||
if(sudp < 0)
|
||||
|
18
scanner.c
18
scanner.c
@ -716,3 +716,21 @@ ScanDirectory(const char * dir, const char * parent, enum media_types type)
|
||||
printf("Scanning %s finished!\n", dir);
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
start_scanner()
|
||||
{
|
||||
struct media_dir_s * media_path = media_dirs;
|
||||
|
||||
scanning = 1;
|
||||
freopen("/dev/null", "a", stderr);
|
||||
while( media_path )
|
||||
{
|
||||
ScanDirectory(media_path->path, NULL, media_path->type);
|
||||
media_path = media_path->next;
|
||||
}
|
||||
freopen("/proc/self/fd/2", "a", stderr);
|
||||
scanning = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ insert_file(char * name, const char * path, const char * parentID, int object);
|
||||
int
|
||||
CreateDatabase(void);
|
||||
|
||||
void
|
||||
ScanDirectory(const char * dir, const char * parent, enum media_types type);
|
||||
void *
|
||||
start_scanner();
|
||||
|
||||
#endif
|
||||
|
@ -39,4 +39,5 @@ sqlite3 * db;
|
||||
char friendly_name[FRIENDLYNAME_MAX_LEN];
|
||||
struct media_dir_s * media_dirs = NULL;
|
||||
struct album_art_name_s * album_art_names = NULL;
|
||||
short int scanning = 0;
|
||||
__u32 updateID = 0;
|
||||
|
@ -85,6 +85,7 @@ extern sqlite3 *db;
|
||||
extern char friendly_name[];
|
||||
extern struct media_dir_s * media_dirs;
|
||||
extern struct album_art_name_s * album_art_names;
|
||||
extern short int scanning;
|
||||
extern __u32 updateID;
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user