* Allow the user to specify where to keep the database in the config file.

This commit is contained in:
Justin Maggard 2009-11-19 03:22:35 +00:00
parent 808fc6f459
commit 902b2105df
10 changed files with 50 additions and 19 deletions

View File

@ -37,7 +37,7 @@
int
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");
return (!access(*cache_file, F_OK));

View File

@ -143,7 +143,7 @@ echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
echo "" >> ${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 "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}

2
log.c
View File

@ -122,7 +122,7 @@ log_err(int level, enum _log_facility facility, char *fname, int lineno, char *f
time_t t;
struct tm *tm;
if (level && level>log_level[facility])
if (level && level>log_level[facility] && level>E_FATAL)
return;
if (!log_fp)

View File

@ -197,10 +197,19 @@ getfriendlyname(char * buf, int len)
#endif
}
void
int
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");
}
@ -209,6 +218,7 @@ open_db(void)
sql_exec(db, "pragma journal_mode = OFF");
sql_exec(db, "pragma synchronous = OFF;");
sql_exec(db, "pragma default_cache_size = 8192;");
return new_db;
}
/* init phase :
@ -385,6 +395,18 @@ init(int argc, char * * argv)
}
}
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:
if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) )
CLEARFLAG(INOTIFY_MASK);
@ -533,7 +555,8 @@ init(int argc, char * * argv)
runtime_vars.port = 0; // triggers help display
break;
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;
case 'V':
printf("Version " MINIDLNA_VERSION "\n");
@ -596,7 +619,10 @@ init(int argc, char * * argv)
#ifdef READYNAS
log_init("/var/log/upnp-av.log", "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn");
#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
}
@ -618,7 +644,7 @@ init(int argc, char * * argv)
{
#ifdef READYNAS
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
"https://%s/admin/", lan_addr[0].str);
"http://%s/admin/", lan_addr[0].str);
#else
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
"http://%s:%d/", lan_addr[0].str, runtime_vars.port);
@ -694,14 +720,7 @@ main(int argc, char * * argv)
#endif
LIST_INIT(&upnphttphead);
if( access(DB_PATH, F_OK) != 0 )
{
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();
new_db = open_db();
if( !new_db )
{
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");
}
sqlite3_close(db);
unlink(DB_PATH "/files.db");
system("rm -rf " DB_PATH "/art_cache");
char *cmd;
asprintf(&cmd, "rm -rf %s/files.db %s/art_cache", db_path, db_path);
system(cmd);
free(cmd);
open_db();
if( CreateDatabase() != 0 )
{

View File

@ -16,6 +16,9 @@ media_dir=/opt
# set this if you want to customize the name that shows up on your clients
#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
# 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

View File

@ -33,6 +33,7 @@ static const struct {
{ UPNPMEDIADIR, "media_dir"},
{ UPNPALBUMART_NAMES, "album_art_names"},
{ UPNPINOTIFY, "inotify" },
{ UPNPDBDIR, "db_dir" },
{ ENABLE_TIVO, "enable_tivo" },
{ ENABLE_DLNA_STRICT, "strict_dlna" }
};

View File

@ -26,6 +26,7 @@ enum upnpconfigoptions {
UPNPMEDIADIR, /* directory to search for UPnP-A/V content */
UPNPALBUMART_NAMES, /* list of '/'-delimited file names to check for album art */
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_DLNA_STRICT /* strictly adhere to DLNA specs */
};

View File

@ -12,6 +12,7 @@
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <linux/limits.h>
#include "config.h"
#include "upnpglobalvars.h"
@ -43,6 +44,7 @@ struct lan_addr_s lan_addr[MAX_LAN_ADDR];
sqlite3 * db;
char dlna_no_conv[] = "DLNA.ORG_OP=01;DLNA.ORG_CI=0";
char friendly_name[FRIENDLYNAME_MAX_LEN];
char db_path[PATH_MAX] = DEFAULT_DB_PATH;
struct media_dir_s * media_dirs = NULL;
struct album_art_name_s * album_art_names = NULL;
struct client_cache_s clients[CLIENT_CACHE_SLOTS];

View File

@ -116,6 +116,7 @@ extern sqlite3 *db;
extern char dlna_no_conv[];
#define FRIENDLYNAME_MAX_LEN (64)
extern char friendly_name[];
extern char db_path[];
extern struct media_dir_s * media_dirs;
extern struct album_art_name_s * album_art_names;
extern struct client_cache_s clients[CLIENT_CACHE_SLOTS];

View File

@ -19,6 +19,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <linux/limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
@ -27,6 +28,7 @@
#include <errno.h>
#include "minidlnatypes.h"
#include "log.h"
int
ends_with(const char * haystack, const char * needle)
@ -198,7 +200,7 @@ make_dir(char * path, mode_t mode)
} 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;
}