fix of removing sub-direcory

git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@1000 a7169a2c-3604-0410-bc95-c702d8d87f7a
This commit is contained in:
drotos 2007-01-15 13:36:51 +00:00 committed by Adam Visegradi
parent 2b97eb0f17
commit 1f812e4950
1 changed files with 15 additions and 1 deletions

View File

@ -74,19 +74,29 @@ _DC_rmsubdir(char *name)
int i= 0;
if ((d= opendir(name)) == NULL)
{
DC_log(LOG_DEBUG, "Open %s: %s", name, strerror(errno));
return(0);
}
while ((de= readdir(d)))
{
if (strcmp(de->d_name, ".") != 0 &&
strcmp(de->d_name, "..") != 0)
{
i+= _DC_rm(de->d_name);
char *s= malloc(strlen(name)+strlen(de->d_name) + 10);
strcpy(s, name);
strcat(s, "/");
strcat(s, de->d_name);
i+= _DC_rm(s);
free(s);
}
}
closedir(d);
if (rmdir(name))
{
DC_log(LOG_ERR, "Failed to rmdir %s: %s",
name, strerror(errno));
}
return(i);
}
@ -101,11 +111,15 @@ _DC_rm(char *name)
return(0);
i= lstat(name, &s);
if (i != 0)
{
return(0);
}
if (S_ISDIR(s.st_mode) &&
strcmp(name, ".") != 0 &&
strcmp(name, "..") != 0)
{
return(_DC_rmsubdir(name));
}
else
{
if (remove(name))