* Allow the user to specify where to keep the database in the config file.
This commit is contained in:
parent
808fc6f459
commit
902b2105df
@ -37,7 +37,7 @@
|
|||||||
int
|
int
|
||||||
art_cache_exists(const char * orig_path, char ** cache_file)
|
art_cache_exists(const char * orig_path, char ** cache_file)
|
||||||
{
|
{
|
||||||
asprintf(cache_file, DB_PATH "/art_cache%s", orig_path);
|
asprintf(cache_file, "%s/art_cache%s", db_path, orig_path);
|
||||||
strcpy(strchr(*cache_file, '\0')-4, ".jpg");
|
strcpy(strchr(*cache_file, '\0')-4, ".jpg");
|
||||||
|
|
||||||
return (!access(*cache_file, F_OK));
|
return (!access(*cache_file, F_OK));
|
||||||
|
@ -143,7 +143,7 @@ echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
|
|||||||
echo "" >> ${CONFIGFILE}
|
echo "" >> ${CONFIGFILE}
|
||||||
|
|
||||||
echo "/* full path of the file database */" >> ${CONFIGFILE}
|
echo "/* full path of the file database */" >> ${CONFIGFILE}
|
||||||
echo "#define DB_PATH \"${DB_PATH}\"" >> ${CONFIGFILE}
|
echo "#define DEFAULT_DB_PATH \"${DB_PATH}\"" >> ${CONFIGFILE}
|
||||||
echo "" >> ${CONFIGFILE}
|
echo "" >> ${CONFIGFILE}
|
||||||
|
|
||||||
echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
|
echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
|
||||||
|
2
log.c
2
log.c
@ -122,7 +122,7 @@ log_err(int level, enum _log_facility facility, char *fname, int lineno, char *f
|
|||||||
time_t t;
|
time_t t;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
|
|
||||||
if (level && level>log_level[facility])
|
if (level && level>log_level[facility] && level>E_FATAL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!log_fp)
|
if (!log_fp)
|
||||||
|
51
minidlna.c
51
minidlna.c
@ -197,10 +197,19 @@ getfriendlyname(char * buf, int len)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
open_db(void)
|
open_db(void)
|
||||||
{
|
{
|
||||||
if( sqlite3_open(DB_PATH "/files.db", &db) != SQLITE_OK )
|
char path[PATH_MAX];
|
||||||
|
int new_db = 0;
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path), "%s/files.db", db_path);
|
||||||
|
if( access(path, F_OK) != 0 )
|
||||||
|
{
|
||||||
|
new_db = 1;
|
||||||
|
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
|
||||||
|
}
|
||||||
|
if( sqlite3_open(path, &db) != SQLITE_OK )
|
||||||
{
|
{
|
||||||
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n");
|
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n");
|
||||||
}
|
}
|
||||||
@ -209,6 +218,7 @@ open_db(void)
|
|||||||
sql_exec(db, "pragma journal_mode = OFF");
|
sql_exec(db, "pragma journal_mode = OFF");
|
||||||
sql_exec(db, "pragma synchronous = OFF;");
|
sql_exec(db, "pragma synchronous = OFF;");
|
||||||
sql_exec(db, "pragma default_cache_size = 8192;");
|
sql_exec(db, "pragma default_cache_size = 8192;");
|
||||||
|
return new_db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init phase :
|
/* init phase :
|
||||||
@ -385,6 +395,18 @@ init(int argc, char * * argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case UPNPDBDIR:
|
||||||
|
path = realpath(ary_options[i].value, real_path);
|
||||||
|
if( !path )
|
||||||
|
path = (ary_options[i].value);
|
||||||
|
make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
|
||||||
|
if( access(path, F_OK) != 0 )
|
||||||
|
{
|
||||||
|
DPRINTF(E_FATAL, L_GENERAL, "Database path not accessible! [%s]\n", path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
strncpy(db_path, path, PATH_MAX);
|
||||||
|
break;
|
||||||
case UPNPINOTIFY:
|
case UPNPINOTIFY:
|
||||||
if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) )
|
if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) )
|
||||||
CLEARFLAG(INOTIFY_MASK);
|
CLEARFLAG(INOTIFY_MASK);
|
||||||
@ -533,7 +555,8 @@ init(int argc, char * * argv)
|
|||||||
runtime_vars.port = 0; // triggers help display
|
runtime_vars.port = 0; // triggers help display
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
system("rm -rf " DB_PATH); // triggers a full rescan
|
snprintf(real_path, sizeof(real_path), "rm -rf %s", db_path);
|
||||||
|
system(real_path);
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
printf("Version " MINIDLNA_VERSION "\n");
|
printf("Version " MINIDLNA_VERSION "\n");
|
||||||
@ -596,7 +619,10 @@ init(int argc, char * * argv)
|
|||||||
#ifdef READYNAS
|
#ifdef READYNAS
|
||||||
log_init("/var/log/upnp-av.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn");
|
log_init("/var/log/upnp-av.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn");
|
||||||
#else
|
#else
|
||||||
log_init(DB_PATH "/minidlna.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn");
|
if( access(db_path, F_OK) != 0 )
|
||||||
|
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
|
||||||
|
sprintf(real_path, "%s/minidlna.log", db_path);
|
||||||
|
log_init(real_path, "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,7 +644,7 @@ init(int argc, char * * argv)
|
|||||||
{
|
{
|
||||||
#ifdef READYNAS
|
#ifdef READYNAS
|
||||||
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
|
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
|
||||||
"https://%s/admin/", lan_addr[0].str);
|
"http://%s/admin/", lan_addr[0].str);
|
||||||
#else
|
#else
|
||||||
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
|
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
|
||||||
"http://%s:%d/", lan_addr[0].str, runtime_vars.port);
|
"http://%s:%d/", lan_addr[0].str, runtime_vars.port);
|
||||||
@ -694,14 +720,7 @@ main(int argc, char * * argv)
|
|||||||
#endif
|
#endif
|
||||||
LIST_INIT(&upnphttphead);
|
LIST_INIT(&upnphttphead);
|
||||||
|
|
||||||
if( access(DB_PATH, F_OK) != 0 )
|
new_db = open_db();
|
||||||
{
|
|
||||||
char *db_path = strdup(DB_PATH);
|
|
||||||
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
|
|
||||||
free(db_path);
|
|
||||||
new_db = 1;
|
|
||||||
}
|
|
||||||
open_db();
|
|
||||||
if( !new_db )
|
if( !new_db )
|
||||||
{
|
{
|
||||||
updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS");
|
updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS");
|
||||||
@ -717,8 +736,10 @@ main(int argc, char * * argv)
|
|||||||
DPRINTF(E_WARN, L_GENERAL, "Database version mismatch; need to recreate...\n");
|
DPRINTF(E_WARN, L_GENERAL, "Database version mismatch; need to recreate...\n");
|
||||||
}
|
}
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
unlink(DB_PATH "/files.db");
|
char *cmd;
|
||||||
system("rm -rf " DB_PATH "/art_cache");
|
asprintf(&cmd, "rm -rf %s/files.db %s/art_cache", db_path, db_path);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
open_db();
|
open_db();
|
||||||
if( CreateDatabase() != 0 )
|
if( CreateDatabase() != 0 )
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,9 @@ media_dir=/opt
|
|||||||
# set this if you want to customize the name that shows up on your clients
|
# set this if you want to customize the name that shows up on your clients
|
||||||
#friendly_name=My DLNA Server
|
#friendly_name=My DLNA Server
|
||||||
|
|
||||||
|
# set this if you would like to specify the directory where you want MiniDLNA to store its database and album art cache
|
||||||
|
#db_dir=/var/cache/minidlna
|
||||||
|
|
||||||
# this should be a list of file names to check for when searching for album art
|
# this should be a list of file names to check for when searching for album art
|
||||||
# note: names should be delimited with a forward slash ("/")
|
# note: names should be delimited with a forward slash ("/")
|
||||||
album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg
|
album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg
|
||||||
|
@ -33,6 +33,7 @@ static const struct {
|
|||||||
{ UPNPMEDIADIR, "media_dir"},
|
{ UPNPMEDIADIR, "media_dir"},
|
||||||
{ UPNPALBUMART_NAMES, "album_art_names"},
|
{ UPNPALBUMART_NAMES, "album_art_names"},
|
||||||
{ UPNPINOTIFY, "inotify" },
|
{ UPNPINOTIFY, "inotify" },
|
||||||
|
{ UPNPDBDIR, "db_dir" },
|
||||||
{ ENABLE_TIVO, "enable_tivo" },
|
{ ENABLE_TIVO, "enable_tivo" },
|
||||||
{ ENABLE_DLNA_STRICT, "strict_dlna" }
|
{ ENABLE_DLNA_STRICT, "strict_dlna" }
|
||||||
};
|
};
|
||||||
|
@ -26,6 +26,7 @@ enum upnpconfigoptions {
|
|||||||
UPNPMEDIADIR, /* directory to search for UPnP-A/V content */
|
UPNPMEDIADIR, /* directory to search for UPnP-A/V content */
|
||||||
UPNPALBUMART_NAMES, /* list of '/'-delimited file names to check for album art */
|
UPNPALBUMART_NAMES, /* list of '/'-delimited file names to check for album art */
|
||||||
UPNPINOTIFY, /* enable inotify on the media directories */
|
UPNPINOTIFY, /* enable inotify on the media directories */
|
||||||
|
UPNPDBDIR, /* base directory to store the database, log files, and album art cache */
|
||||||
ENABLE_TIVO, /* enable support for streaming images and music to TiVo */
|
ENABLE_TIVO, /* enable support for streaming images and music to TiVo */
|
||||||
ENABLE_DLNA_STRICT /* strictly adhere to DLNA specs */
|
ENABLE_DLNA_STRICT /* strictly adhere to DLNA specs */
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "upnpglobalvars.h"
|
#include "upnpglobalvars.h"
|
||||||
@ -43,6 +44,7 @@ struct lan_addr_s lan_addr[MAX_LAN_ADDR];
|
|||||||
sqlite3 * db;
|
sqlite3 * db;
|
||||||
char dlna_no_conv[] = "DLNA.ORG_OP=01;DLNA.ORG_CI=0";
|
char dlna_no_conv[] = "DLNA.ORG_OP=01;DLNA.ORG_CI=0";
|
||||||
char friendly_name[FRIENDLYNAME_MAX_LEN];
|
char friendly_name[FRIENDLYNAME_MAX_LEN];
|
||||||
|
char db_path[PATH_MAX] = DEFAULT_DB_PATH;
|
||||||
struct media_dir_s * media_dirs = NULL;
|
struct media_dir_s * media_dirs = NULL;
|
||||||
struct album_art_name_s * album_art_names = NULL;
|
struct album_art_name_s * album_art_names = NULL;
|
||||||
struct client_cache_s clients[CLIENT_CACHE_SLOTS];
|
struct client_cache_s clients[CLIENT_CACHE_SLOTS];
|
||||||
|
@ -116,6 +116,7 @@ extern sqlite3 *db;
|
|||||||
extern char dlna_no_conv[];
|
extern char dlna_no_conv[];
|
||||||
#define FRIENDLYNAME_MAX_LEN (64)
|
#define FRIENDLYNAME_MAX_LEN (64)
|
||||||
extern char friendly_name[];
|
extern char friendly_name[];
|
||||||
|
extern char db_path[];
|
||||||
extern struct media_dir_s * media_dirs;
|
extern struct media_dir_s * media_dirs;
|
||||||
extern struct album_art_name_s * album_art_names;
|
extern struct album_art_name_s * album_art_names;
|
||||||
extern struct client_cache_s clients[CLIENT_CACHE_SLOTS];
|
extern struct client_cache_s clients[CLIENT_CACHE_SLOTS];
|
||||||
|
4
utils.c
4
utils.c
@ -19,6 +19,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -27,6 +28,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "minidlnatypes.h"
|
#include "minidlnatypes.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
ends_with(const char * haystack, const char * needle)
|
ends_with(const char * haystack, const char * needle)
|
||||||
@ -198,7 +200,7 @@ make_dir(char * path, mode_t mode)
|
|||||||
|
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
printf("make_dir: cannot create directory '%s'", path);
|
DPRINTF(E_WARN, L_GENERAL, "make_dir: cannot create directory '%s'\n", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user