don't stat() the db to get the modtime everytime, instead store it when we read the db
git-svn-id: https://svn.musicpd.org/mpd/trunk@779 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
be3e2f08c9
commit
5ea8e2d65b
@ -70,7 +70,9 @@ typedef struct _Directory {
|
|||||||
|
|
||||||
Directory * mp3rootDirectory = NULL;
|
Directory * mp3rootDirectory = NULL;
|
||||||
|
|
||||||
char * directorydb;
|
char * directory_db;
|
||||||
|
|
||||||
|
time_t directory_dbModTime = 0;
|
||||||
|
|
||||||
volatile int directory_updatePid = 0;
|
volatile int directory_updatePid = 0;
|
||||||
|
|
||||||
@ -140,10 +142,16 @@ void directory_sigChldHandler(int pid, int status) {
|
|||||||
|
|
||||||
void readDirectoryDBIfUpdateIsFinished() {
|
void readDirectoryDBIfUpdateIsFinished() {
|
||||||
if(directory_reReadDB && 0==directory_updatePid) {
|
if(directory_reReadDB && 0==directory_updatePid) {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
DEBUG("readDirectoryDB since update finished successfully\n");
|
DEBUG("readDirectoryDB since update finished successfully\n");
|
||||||
readDirectoryDB();
|
readDirectoryDB();
|
||||||
incrPlaylistVersion();
|
incrPlaylistVersion();
|
||||||
directory_reReadDB = 0;
|
directory_reReadDB = 0;
|
||||||
|
|
||||||
|
if(stat(directory_db,&st)==0) {
|
||||||
|
directory_dbModTime = st.st_mtime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +190,7 @@ int updateInit(FILE * fp, List * pathList) {
|
|||||||
ignoreSignals();
|
ignoreSignals();
|
||||||
if(writeDirectoryDB()<0) {
|
if(writeDirectoryDB()<0) {
|
||||||
ERROR("problems writing music db file, \"%s\"\n",
|
ERROR("problems writing music db file, \"%s\"\n",
|
||||||
directorydb);
|
directory_db);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -790,7 +798,7 @@ int writeDirectoryDB() {
|
|||||||
deleteEmptyDirectoriesInDirectory(mp3rootDirectory);
|
deleteEmptyDirectoriesInDirectory(mp3rootDirectory);
|
||||||
sortDirectory(mp3rootDirectory);
|
sortDirectory(mp3rootDirectory);
|
||||||
|
|
||||||
while(!(fp=fopen(directorydb,"w")) && errno==EINTR);
|
while(!(fp=fopen(directory_db,"w")) && errno==EINTR);
|
||||||
if(!fp) return -1;
|
if(!fp) return -1;
|
||||||
|
|
||||||
/* block signals when writing the db so we don't get a corrupted db*/
|
/* block signals when writing the db so we don't get a corrupted db*/
|
||||||
@ -810,7 +818,7 @@ int readDirectoryDB() {
|
|||||||
FILE * fp;
|
FILE * fp;
|
||||||
|
|
||||||
if(!mp3rootDirectory) mp3rootDirectory = newDirectory(NULL,0);
|
if(!mp3rootDirectory) mp3rootDirectory = newDirectory(NULL,0);
|
||||||
while(!(fp=fopen(directorydb,"r")) && errno==EINTR);
|
while(!(fp=fopen(directory_db,"r")) && errno==EINTR);
|
||||||
if(!fp) return -1;
|
if(!fp) return -1;
|
||||||
|
|
||||||
/* get initial info */
|
/* get initial info */
|
||||||
@ -898,7 +906,7 @@ int updateMp3Directory(FILE * fp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(writeDirectoryDB()<0) {
|
if(writeDirectoryDB()<0) {
|
||||||
ERROR("problems writing music db file, \"%s\"\n",directorydb);
|
ERROR("problems writing music db file, \"%s\"\n",directory_db);
|
||||||
myfprintf(fp,"%s problems writing music db\n",COMMAND_RESPOND_ERROR);
|
myfprintf(fp,"%s problems writing music db\n",COMMAND_RESPOND_ERROR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1124,10 +1132,14 @@ unsigned long sumSongTimesIn(FILE * fp, char * name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initMp3Directory() {
|
void initMp3Directory() {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
mp3rootDirectory = newDirectory(NULL,0);
|
mp3rootDirectory = newDirectory(NULL,0);
|
||||||
exploreDirectory(mp3rootDirectory);
|
exploreDirectory(mp3rootDirectory);
|
||||||
stats.numberOfSongs = countSongsIn(stderr,NULL);
|
stats.numberOfSongs = countSongsIn(stderr,NULL);
|
||||||
stats.dbPlayTime = sumSongTimesIn(stderr,NULL);
|
stats.dbPlayTime = sumSongTimesIn(stderr,NULL);
|
||||||
|
|
||||||
|
if(stat(directory_db,&st)==0) directory_dbModTime = st.st_mtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
Song * getSongDetails(char * file, char ** shortnameRet,
|
Song * getSongDetails(char * file, char ** shortnameRet,
|
||||||
@ -1175,11 +1187,6 @@ Song * getSong(char * file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
time_t getDbModTime() {
|
time_t getDbModTime() {
|
||||||
time_t mtime = 0;
|
return directory_dbModTime;
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if(stat(directorydb,&st)==0) mtime = st.st_mtime;
|
|
||||||
|
|
||||||
return mtime;
|
|
||||||
}
|
}
|
||||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
extern char * directorydb;
|
extern char * directory_db;
|
||||||
|
|
||||||
void readDirectoryDBIfUpdateIsFinished();
|
void readDirectoryDBIfUpdateIsFinished();
|
||||||
|
|
||||||
|
@ -306,8 +306,8 @@ int main(int argc, char * argv[]) {
|
|||||||
initTables();
|
initTables();
|
||||||
initPlaylist();
|
initPlaylist();
|
||||||
|
|
||||||
if(!options.dbFile) directorydb = strdup(rpp2app(".mpddb"));
|
if(!options.dbFile) directory_db = strdup(rpp2app(".mpddb"));
|
||||||
else directorydb = strdup(options.dbFile);
|
else directory_db = strdup(options.dbFile);
|
||||||
|
|
||||||
if(options.createDB>0 || options.onlyCreateDB || readDirectoryDB()<0)
|
if(options.createDB>0 || options.onlyCreateDB || readDirectoryDB()<0)
|
||||||
{
|
{
|
||||||
|
@ -142,5 +142,7 @@ int getPlayerBits();
|
|||||||
|
|
||||||
int getPlayerChannels();
|
int getPlayerChannels();
|
||||||
|
|
||||||
|
void playerCycleLogFiles();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
||||||
|
Loading…
Reference in New Issue
Block a user