Better error reporting, and now handles files or directories.
This commit is contained in:
parent
cdeea64242
commit
9fd1a3ecda
10
nuke.c
10
nuke.c
@ -4,9 +4,10 @@
|
||||
*/
|
||||
|
||||
#include "colors.h"
|
||||
#include "list.h"
|
||||
#include "globe.h"
|
||||
#include "list.h"
|
||||
#include <curses.h>
|
||||
#include <errno.h>
|
||||
#include <ftw.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
@ -115,7 +116,12 @@ int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW
|
||||
|
||||
int rmrf(char *path)
|
||||
{
|
||||
DIR *dir;
|
||||
if (!(dir = opendir(path))) {
|
||||
return remove(path);
|
||||
} else {
|
||||
return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -446,7 +452,7 @@ exit_success:
|
||||
if (rmrf(argv[i]) == 0) {
|
||||
printf("deleted %s\n", argv[i]);
|
||||
} else {
|
||||
printf("unable to delete %s\n", argv[i]);
|
||||
printf("unable to delete %s\n (%s)", argv[i], strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user