From c39194fd445321b4fc2ee9ab597d44c771402e3d Mon Sep 17 00:00:00 2001 From: Fedor Date: Sun, 5 Sep 2010 02:14:03 -0400 Subject: [PATCH] MiniDLNA: add utility functions to create scan flags --- release/src/router/minidlna/inotify.c | 2 ++ release/src/router/minidlna/scanner.c | 23 +++-------------------- release/src/router/minidlna/utils.c | 31 +++++++++++++++++++++++++++++++ release/src/router/minidlna/utils.h | 6 ++++++ 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/release/src/router/minidlna/inotify.c b/release/src/router/minidlna/inotify.c index 6f5321e9be..6caab4992f 100644 --- a/release/src/router/minidlna/inotify.c +++ b/release/src/router/minidlna/inotify.c @@ -700,12 +700,14 @@ start_inotify() (event->mask & IN_MOVED_TO && event->mask & IN_ISDIR) ) { DPRINTF(E_DEBUG, L_INOTIFY, "The directory %s was %s.\n", path_buf, (event->mask & IN_MOVED_TO ? "moved here" : "created")); + begin_scan(); /* This could be a directory created by auto-mount. * It will be empty until the drive is mounted to this directory. * So let's wait a few seconds to allow mount to complete. */ sleep(5); inotify_insert_directory(pollfds[0].fd, esc_name, path_buf); + end_scan(); } else if ( event->mask & IN_CLOSE_WRITE || event->mask & IN_MOVED_TO ) { diff --git a/release/src/router/minidlna/scanner.c b/release/src/router/minidlna/scanner.c index e97a0a529d..7373b12621 100644 --- a/release/src/router/minidlna/scanner.c +++ b/release/src/router/minidlna/scanner.c @@ -801,19 +801,7 @@ start_scanner() if (setpriority(PRIO_PROCESS, 0, 15) == -1) DPRINTF(E_WARN, L_INOTIFY, "Failed to reduce scanner thread priority\n"); -#ifdef READYNAS - FILE * flag = fopen("/ramfs/.upnp-av_scan", "w"); - if( flag ) - fclose(flag); -#else - mkdir("/var/notice", 0755); - FILE * flag = fopen("/var/notice/dlna", "w"); - if( flag ) - { - fprintf(flag, "Scan in progress"); - fclose(flag); - } -#endif + begin_scan(); freopen("/dev/null", "a", stderr); while( media_path ) { @@ -821,13 +809,8 @@ start_scanner() media_path = media_path->next; } freopen("/proc/self/fd/2", "a", stderr); -#ifdef READYNAS - if( access("/ramfs/.rescan_done", F_OK) == 0 ) - system("/bin/sh /ramfs/.rescan_done"); - unlink("/ramfs/.upnp-av_scan"); -#else - unlink("/var/notice/dlna"); -#endif + end_scan(); + /* 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). */ diff --git a/release/src/router/minidlna/utils.c b/release/src/router/minidlna/utils.c index 80def25881..ac45c9ea96 100644 --- a/release/src/router/minidlna/utils.c +++ b/release/src/router/minidlna/utils.c @@ -306,3 +306,34 @@ resolve_unknown_type(const char * path, enum media_types dir_type) return type; } +void +begin_scan() +{ + FILE * flag; + +#ifdef READYNAS + flag = fopen("/ramfs/.upnp-av_scan", "w"); + if( flag ) + fclose(flag); +#else + mkdir("/var/notice", 0755); + flag = fopen("/var/notice/dlna", "w"); + if( flag ) + { + fprintf(flag, "Scan in progress"); + fclose(flag); + } +#endif +} + +void +end_scan() +{ +#ifdef READYNAS + if( access("/ramfs/.rescan_done", F_OK) == 0 ) + system("/bin/sh /ramfs/.rescan_done"); + unlink("/ramfs/.upnp-av_scan"); +#else + unlink("/var/notice/dlna"); +#endif +} diff --git a/release/src/router/minidlna/utils.h b/release/src/router/minidlna/utils.h index 7cc34d04b9..1d318df468 100644 --- a/release/src/router/minidlna/utils.h +++ b/release/src/router/minidlna/utils.h @@ -46,4 +46,10 @@ is_playlist(const char * file); int resolve_unknown_type(const char * path, enum media_types dir_type); +void +begin_scan(); + +void +end_scan(); + #endif -- 2.11.4.GIT