- if ((buf.st_mode&S_IFMT) == S_IFDIR) {
- if (!rflg) {
- if (!fflg) {
- fprintf(stderr, "rm: %s directory\n", arg);
- errcode++;
- }
- return (0);
- }
- if (iflg && level != 0) {
- printf("rm: remove directory %s? ", arg);
- if (!yes())
- return (0); /* didn't remove everything */
- }
- if (access(arg, R_OK|W_OK|X_OK) != 0) {
- if (rmdir(arg) == 0)
- return (1); /* salvaged: removed empty dir */
- if (!fflg) {
- fprintf(stderr, "rm: %s not removed: %s\n", arg,
- strerror(errno));
- errcode++;
- }
- return (0); /* error */
- }
- if ((dirp = opendir(arg)) == NULL) {
- if (!fflg) {
- fprintf(stderr, "rm: cannot read %s: %s\n",
- arg, strerror(errno));
- errcode++;
- }
- return (0);
- }
- if (level == 0)
- append(arg);
- prevname[0] = '\0';
- while ((dp = readdir(dirp)) != NULL) {
- if (isdot(dp->d_name)) {
- strcpy(prevname, dp->d_name);
- continue;
- }
- append(dp->d_name);
- closedir(dirp);
- ok = rm(path, level + 1);
- for (cp = pathp; *--cp != '/' && cp > path; )
- ;
- pathp = cp;
- *cp++ = '\0';
- if ((dirp = opendir(arg)) == NULL) {
- if (!fflg) {
- fprintf(stderr,
- "rm: cannot reopen %s?: %s\n",
- arg, strerror(errno));
- errcode++;
- }
+ while (p = fts_read(fts)) {
+ switch(p->fts_info) {
+ case FTS_DC:
+ case FTS_DNR:
+ case FTS_DNX:
+ break;
+ case FTS_ERR:
+ error(p->fts_path, errno);
+ exit(1);
+ /*
+ * FTS_NS: assume that if can't stat the file, it can't be
+ * unlinked. If we need stat information, should never see
+ * FTS_NS (unless a file specified as an argument doesn't
+ * exist), since such files are in directories that will be
+ * returned FTS_DNX.
+ */
+ case FTS_NS:
+ if (!needstat)