From 8933f5d416acf1f6ee66965137d1de7a9dc05989 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 22 Jun 2004 01:04:13 +0000 Subject: only call opendir() once when updating git-svn-id: https://svn.musicpd.org/mpd/trunk@1608 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/directory.c b/src/directory.c index 28d3135f1..34efa27dd 100644 --- a/src/directory.c +++ b/src/directory.c @@ -338,8 +338,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { 0 -> no error, but nothing removed 1 -> no error, and stuff removed */ -int removeDeletedFromDirectory(Directory * directory) { - DIR * dir; +int removeDeletedFromDirectory(Directory * directory, DIR * dir) { char cwd[2]; struct dirent * ent; char * dirname = directory->utf8name; @@ -355,8 +354,6 @@ int removeDeletedFromDirectory(Directory * directory) { cwd[1] = '\0'; if(dirname==NULL) dirname=cwd; - if((dir = opendir(rmp2amp(utf8ToFsCharset(dirname))))==NULL) return -1; - while((ent = readdir(dir))) { if(ent->d_name[0]=='.') continue; /* hide hidden stuff */ if(strchr(ent->d_name, '\n')) continue; @@ -373,8 +370,6 @@ int removeDeletedFromDirectory(Directory * directory) { insertInList(entList,utf8,s); } - closedir(dir); - node = directory->subDirectories->firstNode; while(node) { tmpNode = node->nextNode; @@ -556,10 +551,12 @@ int updateDirectory(Directory * directory) { cwd[1] = '\0'; if(dirname==NULL) dirname=cwd; - if(removeDeletedFromDirectory(directory)>0) ret = 1; - if((dir = opendir(rmp2amp(utf8ToFsCharset(dirname))))==NULL) return -1; + if(removeDeletedFromDirectory(directory, dir)>0) ret = 1; + + rewinddir(dir); + while((ent = readdir(dir))) { if(ent->d_name[0]=='.') continue; /* hide hidden stuff */ if(strchr(ent->d_name, '\n')) continue; -- cgit v1.2.3