fix rm -r
This commit is contained in:
parent
fbb80983ce
commit
78fd8698cc
12
rm.c
12
rm.c
|
@ -39,9 +39,17 @@ void rm(const char *path)
|
||||||
if(remove(path) == 0)
|
if(remove(path) == 0)
|
||||||
return;
|
return;
|
||||||
if(errno == ENOTEMPTY && rflag) {
|
if(errno == ENOTEMPTY && rflag) {
|
||||||
|
char *buf;
|
||||||
|
long size;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
|
|
||||||
|
if((size = pathconf(".", _PC_PATH_MAX)) < 0)
|
||||||
|
size = BUFSIZ;
|
||||||
|
if(!(buf = malloc(size)))
|
||||||
|
eprintf("malloc:");
|
||||||
|
if(!getcwd(buf, size))
|
||||||
|
eprintf("getcwd:");
|
||||||
if(!(dp = opendir(path)))
|
if(!(dp = opendir(path)))
|
||||||
eprintf("opendir %s:", path);
|
eprintf("opendir %s:", path);
|
||||||
if(chdir(path) != 0)
|
if(chdir(path) != 0)
|
||||||
|
@ -51,8 +59,8 @@ void rm(const char *path)
|
||||||
rm(d->d_name);
|
rm(d->d_name);
|
||||||
|
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
if(chdir("..") != 0)
|
if(chdir(buf) != 0)
|
||||||
eprintf("chdir:");
|
eprintf("chdir %s:", buf);
|
||||||
if(remove(path) == 0)
|
if(remove(path) == 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user