fix stateFile path getting garbled
git-svn-id: https://svn.musicpd.org/mpd/trunk@3029 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
@@ -65,9 +65,9 @@
|
|||||||
#define DIRECTORY_RETURN_UPDATE 1
|
#define DIRECTORY_RETURN_UPDATE 1
|
||||||
#define DIRECTORY_RETURN_ERROR -1
|
#define DIRECTORY_RETURN_ERROR -1
|
||||||
|
|
||||||
static Directory * mp3rootDirectory = NULL;
|
Directory * mp3rootDirectory = NULL;
|
||||||
|
|
||||||
static time_t directory_dbModTime = 0;
|
time_t directory_dbModTime = 0;
|
||||||
|
|
||||||
volatile int directory_updatePid = 0;
|
volatile int directory_updatePid = 0;
|
||||||
|
|
||||||
|
16
src/path.c
16
src/path.c
@@ -116,15 +116,15 @@ static char * appendSlash(char ** path) {
|
|||||||
int len = strlen(temp);
|
int len = strlen(temp);
|
||||||
|
|
||||||
if(temp[len-1] != '/') {
|
if(temp[len-1] != '/') {
|
||||||
temp = strdup(*path);
|
temp = malloc(len+2);
|
||||||
|
memset(temp, 0, len+2);
|
||||||
|
memcpy(temp, *path, len);
|
||||||
|
temp[len] = '/';
|
||||||
free(*path);
|
free(*path);
|
||||||
*path = malloc(len+2);
|
*path = temp;
|
||||||
memset(*path, 0, len+2);
|
|
||||||
memcpy(*path, temp, len);
|
|
||||||
(*path)[len] = '/';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return * path;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initPaths() {
|
void initPaths() {
|
||||||
@@ -136,8 +136,8 @@ void initPaths() {
|
|||||||
char * originalLocale;
|
char * originalLocale;
|
||||||
DIR * dir;
|
DIR * dir;
|
||||||
|
|
||||||
musicDir = appendSlash(&musicParam->value);
|
musicDir = appendSlash(&(musicParam->value));
|
||||||
playlistDir = appendSlash(&playlistParam->value);
|
playlistDir = appendSlash(&(playlistParam->value));
|
||||||
|
|
||||||
if((dir = opendir(playlistDir)) == NULL) {
|
if((dir = opendir(playlistDir)) == NULL) {
|
||||||
ERROR("cannot open %s \"%s\" (config line %i): %s\n",
|
ERROR("cannot open %s \"%s\" (config line %i): %s\n",
|
||||||
|
@@ -88,12 +88,18 @@ static int playlist_noGoToNext = 0;
|
|||||||
|
|
||||||
static int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
|
static int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
|
||||||
|
|
||||||
static char * playlist_stateFile = NULL;
|
|
||||||
|
|
||||||
static void swapOrder(int a, int b);
|
static void swapOrder(int a, int b);
|
||||||
static int playPlaylistOrderNumber(FILE * fp, int orderNum);
|
static int playPlaylistOrderNumber(FILE * fp, int orderNum);
|
||||||
static void randomizeOrder(int start, int end);
|
static void randomizeOrder(int start, int end);
|
||||||
|
|
||||||
|
static char * getStateFile() {
|
||||||
|
ConfigParam * param = parseConfigFilePath(CONF_STATE_FILE, 0);
|
||||||
|
|
||||||
|
if(!param) return NULL;
|
||||||
|
|
||||||
|
return param->value;
|
||||||
|
}
|
||||||
|
|
||||||
static void incrPlaylistVersion() {
|
static void incrPlaylistVersion() {
|
||||||
static unsigned long max = ((mpd_uint32)1<<31)-1;
|
static unsigned long max = ((mpd_uint32)1<<31)-1;
|
||||||
playlist.version++;
|
playlist.version++;
|
||||||
@@ -179,8 +185,6 @@ void initPlaylist() {
|
|||||||
|
|
||||||
srandom(time(NULL));
|
srandom(time(NULL));
|
||||||
|
|
||||||
playlist_stateFile = parseConfigFilePath(CONF_STATE_FILE, 0);
|
|
||||||
|
|
||||||
for(i=0; i<playlist_max_length*PLAYLIST_HASH_MULT; i++) {
|
for(i=0; i<playlist_max_length*PLAYLIST_HASH_MULT; i++) {
|
||||||
playlist.idToPosition[i] = -1;
|
playlist.idToPosition[i] = -1;
|
||||||
}
|
}
|
||||||
@@ -252,13 +256,15 @@ int showPlaylist(FILE * fp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void savePlaylistState() {
|
void savePlaylistState() {
|
||||||
if(playlist_stateFile) {
|
char * stateFile = getStateFile();
|
||||||
|
|
||||||
|
if(stateFile) {
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
|
|
||||||
while(!(fp = fopen(playlist_stateFile,"w")) && errno==EINTR);
|
while(!(fp = fopen(stateFile,"w")) && errno==EINTR);
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
ERROR("problems opening state file \"%s\" for "
|
ERROR("problems opening state file \"%s\" for "
|
||||||
"writing: %s\n", playlist_stateFile,
|
"writing: %s\n", stateFile,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -303,16 +309,16 @@ void loadPlaylistFromStateFile(FILE * fp, char * buffer, int state, int current,
|
|||||||
{
|
{
|
||||||
char * temp;
|
char * temp;
|
||||||
int song;
|
int song;
|
||||||
|
char * stateFile = getStateFile();
|
||||||
|
|
||||||
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
|
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
|
||||||
ERROR("error parsing state file \"%s\"\n",playlist_stateFile);
|
ERROR("error parsing state file \"%s\"\n", stateFile);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
while(strcmp(buffer,PLAYLIST_STATE_FILE_PLAYLIST_END)) {
|
while(strcmp(buffer,PLAYLIST_STATE_FILE_PLAYLIST_END)) {
|
||||||
song = atoi(strtok(buffer,":"));
|
song = atoi(strtok(buffer,":"));
|
||||||
if(!(temp = strtok(NULL,""))) {
|
if(!(temp = strtok(NULL,""))) {
|
||||||
ERROR("error parsing state file \"%s\"\n",
|
ERROR("error parsing state file \"%s\"\n", stateFile);
|
||||||
playlist_stateFile);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if(addToPlaylist(stderr, temp, 0)==0 && current==song) {
|
if(addToPlaylist(stderr, temp, 0)==0 && current==song) {
|
||||||
@@ -328,15 +334,16 @@ void loadPlaylistFromStateFile(FILE * fp, char * buffer, int state, int current,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
|
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
|
||||||
ERROR("error parsing state file \"%s\"\n",
|
ERROR("error parsing state file \"%s\"\n", stateFile);
|
||||||
playlist_stateFile);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readPlaylistState() {
|
void readPlaylistState() {
|
||||||
if(playlist_stateFile) {
|
char * stateFile = getStateFile();
|
||||||
|
|
||||||
|
if(stateFile) {
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int current = -1;
|
int current = -1;
|
||||||
@@ -344,17 +351,20 @@ void readPlaylistState() {
|
|||||||
int state = PLAYER_STATE_STOP;
|
int state = PLAYER_STATE_STOP;
|
||||||
char buffer[PLAYLIST_BUFFER_SIZE];
|
char buffer[PLAYLIST_BUFFER_SIZE];
|
||||||
|
|
||||||
if(stat(playlist_stateFile,&st)<0) return;
|
if(stat(stateFile,&st)<0) {
|
||||||
|
DEBUG("failed to stat state file\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!S_ISREG(st.st_mode)) {
|
if(!S_ISREG(st.st_mode)) {
|
||||||
ERROR("state file \"%s\" is not a regular "
|
ERROR("state file \"%s\" is not a regular "
|
||||||
"file\n",playlist_stateFile);
|
"file\n",stateFile);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = fopen(playlist_stateFile,"r");
|
fp = fopen(stateFile,"r");
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
ERROR("problems opening state file \"%s\" for "
|
ERROR("problems opening state file \"%s\" for "
|
||||||
"reading: %s\n", playlist_stateFile,
|
"reading: %s\n", stateFile,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -407,7 +417,7 @@ void readPlaylistState() {
|
|||||||
strlen(PLAYLIST_STATE_FILE_CURRENT)) {
|
strlen(PLAYLIST_STATE_FILE_CURRENT)) {
|
||||||
ERROR("error parsing state "
|
ERROR("error parsing state "
|
||||||
"file \"%s\"\n",
|
"file \"%s\"\n",
|
||||||
playlist_stateFile);
|
stateFile);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
current = atoi(&(buffer
|
current = atoi(&(buffer
|
||||||
|
Reference in New Issue
Block a user