Commit 0473f3ea authored by Warren Dukes's avatar Warren Dukes

don't store only relative paths in the directory structure, its probably not

worth the savings in memory for the extra cpu it requires git-svn-id: https://svn.musicpd.org/mpd/trunk@2630 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent ee26cc33
...@@ -111,7 +111,7 @@ int countSongsInDirectory(FILE * fp, Directory * directory, void * data) { ...@@ -111,7 +111,7 @@ int countSongsInDirectory(FILE * fp, Directory * directory, void * data) {
} }
int printDirectoryInDirectory(FILE * fp, Directory * directory, void * data) { int printDirectoryInDirectory(FILE * fp, Directory * directory, void * data) {
if(directory->name) { if(directory->path) {
myfprintf(fp,"directory: %s\n", getDirectoryPath(directory)); myfprintf(fp,"directory: %s\n", getDirectoryPath(directory));
} }
return 0; return 0;
...@@ -362,7 +362,7 @@ int listAllUniqueTags(FILE * fp, int type, int numConditionals, ...@@ -362,7 +362,7 @@ int listAllUniqueTags(FILE * fp, int type, int numConditionals,
int sumSavedFilenameMemoryInDirectory(FILE * fp, Directory * dir, void * data) { int sumSavedFilenameMemoryInDirectory(FILE * fp, Directory * dir, void * data) {
int * sum = data; int * sum = data;
if(!dir->name) return 0; if(!dir->path) return 0;
*sum += (strlen(getDirectoryPath(dir))+1-sizeof(Directory *))* *sum += (strlen(getDirectoryPath(dir))+1-sizeof(Directory *))*
dir->songs->numberOfNodes; dir->songs->numberOfNodes;
...@@ -390,12 +390,12 @@ void printSavedMemoryFromFilenames() { ...@@ -390,12 +390,12 @@ void printSavedMemoryFromFilenames() {
int sumSavedDirectoryNameMemoryInDirectory(FILE * fp, Directory * dir, void * data) { int sumSavedDirectoryNameMemoryInDirectory(FILE * fp, Directory * dir, void * data) {
int * sum = data; int * sum = data;
if(!dir->name) return 0; if(!dir->path) return 0;
*sum += (strlen(getDirectoryPath(dir))+1)* *sum += (strlen(getDirectoryPath(dir))+1)*
dir->subDirectories->numberOfNodes; dir->subDirectories->numberOfNodes;
*sum += strlen(dir->name)+1; *sum += strlen(dir->path)+1;
return 0; return 0;
} }
......
...@@ -250,8 +250,8 @@ Directory * newDirectory(char * dirname, Directory * parent) { ...@@ -250,8 +250,8 @@ Directory * newDirectory(char * dirname, Directory * parent) {
directory = malloc(sizeof(Directory)); directory = malloc(sizeof(Directory));
if(dirname!=NULL) directory->name = strdup(dirname); if(dirname!=NULL) directory->path = strdup(dirname);
else directory->name = NULL; else directory->path = NULL;
directory->subDirectories = newDirectoryList(); directory->subDirectories = newDirectoryList();
directory->songs = newSongList(); directory->songs = newSongList();
directory->stat = NULL; directory->stat = NULL;
...@@ -263,14 +263,15 @@ Directory * newDirectory(char * dirname, Directory * parent) { ...@@ -263,14 +263,15 @@ Directory * newDirectory(char * dirname, Directory * parent) {
void freeDirectory(Directory * directory) { void freeDirectory(Directory * directory) {
freeDirectoryList(directory->subDirectories); freeDirectoryList(directory->subDirectories);
freeSongList(directory->songs); freeSongList(directory->songs);
if(directory->name) free(directory->name); if(directory->path) free(directory->path);
freeDirectoryStatFromDirectory(directory); freeDirectoryStatFromDirectory(directory);
free(directory); free(directory);
getDirectoryPath(NULL); /* this resets last dir returned */
/*getDirectoryPath(NULL);*/
} }
DirectoryList * newDirectoryList() { DirectoryList * newDirectoryList() {
return makeList((ListFreeDataFunc *)freeDirectory, 0); return makeList((ListFreeDataFunc *)freeDirectory, 1);
} }
void freeDirectoryList(DirectoryList * directoryList) { void freeDirectoryList(DirectoryList * directoryList) {
...@@ -373,13 +374,13 @@ int removeDeletedFromDirectory(Directory * directory, DIR * dir) { ...@@ -373,13 +374,13 @@ int removeDeletedFromDirectory(Directory * directory, DIR * dir) {
if(!utf8) continue; if(!utf8) continue;
if(directory->name) { if(directory->path) {
s = malloc(strlen(getDirectoryPath(directory)) s = malloc(strlen(getDirectoryPath(directory))
+strlen(utf8)+2); +strlen(utf8)+2);
sprintf(s,"%s/%s", getDirectoryPath(directory), utf8); sprintf(s,"%s/%s", getDirectoryPath(directory), utf8);
} }
else s= strdup(utf8); else s= strdup(utf8);
insertInList(entList,utf8,s); insertInList(entList, utf8, s);
} }
node = directory->subDirectories->firstNode; node = directory->subDirectories->firstNode;
...@@ -453,9 +454,9 @@ Directory * addDirectoryPathToDB(char * utf8path, char ** shortname) { ...@@ -453,9 +454,9 @@ Directory * addDirectoryPathToDB(char * utf8path, char ** shortname) {
return NULL; return NULL;
} }
else { else {
directory = newDirectory(*shortname, parentDirectory); directory = newDirectory(utf8path, parentDirectory);
insertInList(parentDirectory->subDirectories, insertInList(parentDirectory->subDirectories,
((Directory *)directory)->name, *shortname,
directory); directory);
} }
} }
...@@ -634,7 +635,7 @@ int updateDirectory(Directory * directory) { ...@@ -634,7 +635,7 @@ int updateDirectory(Directory * directory) {
utf8 = strdup(utf8); utf8 = strdup(utf8);
if(directory->name) { if(directory->path) {
s = malloc(strlen(getDirectoryPath(directory))+ s = malloc(strlen(getDirectoryPath(directory))+
strlen(utf8)+2); strlen(utf8)+2);
sprintf(s,"%s/%s", getDirectoryPath(directory), utf8); sprintf(s,"%s/%s", getDirectoryPath(directory), utf8);
...@@ -684,7 +685,7 @@ int exploreDirectory(Directory * directory) { ...@@ -684,7 +685,7 @@ int exploreDirectory(Directory * directory) {
DEBUG("explore: found: %s (%s)\n",ent->d_name,utf8); DEBUG("explore: found: %s (%s)\n",ent->d_name,utf8);
if(directory->name) { if(directory->path) {
s = malloc(strlen(getDirectoryPath(directory))+ s = malloc(strlen(getDirectoryPath(directory))+
strlen(utf8)+2); strlen(utf8)+2);
sprintf(s,"%s/%s", getDirectoryPath(directory) ,utf8); sprintf(s,"%s/%s", getDirectoryPath(directory) ,utf8);
...@@ -736,7 +737,7 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname, ...@@ -736,7 +737,7 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname,
if(inodeFoundInParent(directory, st->st_ino, st->st_dev)) return 0; if(inodeFoundInParent(directory, st->st_ino, st->st_dev)) return 0;
subDirectory = newDirectory(shortname, directory); subDirectory = newDirectory(name, directory);
subDirectory->stat = newDirectoryStat(st); subDirectory->stat = newDirectoryStat(st);
if(exploreDirectory(subDirectory)<1) { if(exploreDirectory(subDirectory)<1) {
...@@ -744,7 +745,7 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname, ...@@ -744,7 +745,7 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname,
return 0; return 0;
} }
insertInList(directory->subDirectories, subDirectory->name, insertInList(directory->subDirectories, shortname,
subDirectory); subDirectory);
return 1; return 1;
...@@ -863,7 +864,7 @@ void writeDirectoryInfo(FILE * fp, Directory * directory) { ...@@ -863,7 +864,7 @@ void writeDirectoryInfo(FILE * fp, Directory * directory) {
ListNode * node = (directory->subDirectories)->firstNode; ListNode * node = (directory->subDirectories)->firstNode;
Directory * subDirectory; Directory * subDirectory;
if(directory->name) { if(directory->path) {
myfprintf(fp,"%s%s\n", DIRECTORY_BEGIN, myfprintf(fp,"%s%s\n", DIRECTORY_BEGIN,
getDirectoryPath(directory)); getDirectoryPath(directory));
} }
...@@ -877,7 +878,7 @@ void writeDirectoryInfo(FILE * fp, Directory * directory) { ...@@ -877,7 +878,7 @@ void writeDirectoryInfo(FILE * fp, Directory * directory) {
writeSongInfoFromList(fp,directory->songs); writeSongInfoFromList(fp,directory->songs);
if(directory->name) { if(directory->path) {
myfprintf(fp,"%s%s\n", DIRECTORY_END, myfprintf(fp,"%s%s\n", DIRECTORY_END,
getDirectoryPath(directory)); getDirectoryPath(directory));
} }
...@@ -889,6 +890,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { ...@@ -889,6 +890,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
char * key; char * key;
Directory * subDirectory; Directory * subDirectory;
int strcmpRet; int strcmpRet;
char * name;
ListNode * nextDirNode = directory->subDirectories->firstNode; ListNode * nextDirNode = directory->subDirectories->firstNode;
ListNode * nodeTemp; ListNode * nodeTemp;
...@@ -912,8 +914,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { ...@@ -912,8 +914,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
ERROR("Error reading db at line: %s\n",buffer); ERROR("Error reading db at line: %s\n",buffer);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* we ignore the name now name = strdup(&(buffer[strlen(DIRECTORY_BEGIN)]));
name = strdup(&(buffer[strlen(DIRECTORY_BEGIN)]));*/
while(nextDirNode && (strcmpRet = while(nextDirNode && (strcmpRet =
strcmp(key,nextDirNode->key)) > 0) { strcmp(key,nextDirNode->key)) > 0) {
...@@ -924,9 +925,9 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { ...@@ -924,9 +925,9 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
} }
if(NULL==nextDirNode) { if(NULL==nextDirNode) {
subDirectory = newDirectory(key, directory); subDirectory = newDirectory(name, directory);
insertInList(directory->subDirectories, insertInList(directory->subDirectories,
subDirectory->name, key,
(void *)subDirectory); (void *)subDirectory);
} }
else if(strcmpRet == 0) { else if(strcmpRet == 0) {
...@@ -934,11 +935,11 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { ...@@ -934,11 +935,11 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
nextDirNode = nextDirNode->nextNode; nextDirNode = nextDirNode->nextNode;
} }
else { else {
subDirectory = newDirectory(key, directory); subDirectory = newDirectory(name, directory);
insertInListBeforeNode( insertInListBeforeNode(
directory->subDirectories, directory->subDirectories,
nextDirNode, nextDirNode,
subDirectory->name, key,
(void *)subDirectory); (void *)subDirectory);
} }
...@@ -1240,7 +1241,7 @@ time_t getDbModTime() { ...@@ -1240,7 +1241,7 @@ time_t getDbModTime() {
/* pass a NULL to this function to clear the static lastDir, this way /* pass a NULL to this function to clear the static lastDir, this way
* if a directory is freed, and then realloced, the wrong name isn't * if a directory is freed, and then realloced, the wrong name isn't
* output */ * output */
char * getDirectoryPath(Directory * dir) { /*char * getDirectoryPath(Directory * dir) {
static char * buffer = NULL; static char * buffer = NULL;
static int bufferSize = 0; static int bufferSize = 0;
static Directory * lastDir = NULL; static Directory * lastDir = NULL;
...@@ -1258,7 +1259,7 @@ char * getDirectoryPath(Directory * dir) { ...@@ -1258,7 +1259,7 @@ char * getDirectoryPath(Directory * dir) {
while(dir && dir->name) { while(dir && dir->name) {
dlen = strlen(dir->name); dlen = strlen(dir->name);
/* add one for the '/' */ // add one for the '/'
pos -= dlen+1; pos -= dlen+1;
if(pos < 0) { if(pos < 0) {
buffer = realloc(buffer, bufferSize-pos); buffer = realloc(buffer, bufferSize-pos);
...@@ -1277,4 +1278,4 @@ char * getDirectoryPath(Directory * dir) { ...@@ -1277,4 +1278,4 @@ char * getDirectoryPath(Directory * dir) {
lastDir = dir; lastDir = dir;
return buffer+pos+1; return buffer+pos+1;
} }*/
...@@ -35,7 +35,7 @@ typedef struct _DirectoryStat { ...@@ -35,7 +35,7 @@ typedef struct _DirectoryStat {
} DirectoryStat; } DirectoryStat;
typedef struct _Directory { typedef struct _Directory {
char * name; char * path;
DirectoryList * subDirectories; DirectoryList * subDirectories;
SongList * songs; SongList * songs;
struct _Directory * parent; struct _Directory * parent;
...@@ -76,7 +76,8 @@ int traverseAllIn(FILE * fp, char * name, ...@@ -76,7 +76,8 @@ int traverseAllIn(FILE * fp, char * name,
void * data); void * data);
/* don't free this */ /* don't free this */
char * getDirectoryPath(Directory * dir); /*char * getDirectoryPath(Directory * dir);*/
#define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "")
/* free the string that is returned */ /* free the string that is returned */
char * catDirAndFileName(Directory * dir, char * filename); char * catDirAndFileName(Directory * dir, char * filename);
......
...@@ -315,7 +315,7 @@ char * getSongUrl(Song * song) { ...@@ -315,7 +315,7 @@ char * getSongUrl(Song * song) {
return NULL; return NULL;
} }
if(!song->parentDir || !song->parentDir->name) return song->url; if(!song->parentDir || !song->parentDir->path) return song->url;
/* be careful with this!*/ /* be careful with this!*/
if(song == lastSong) return buffer; if(song == lastSong) return buffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment