From 930e3238946d6fd3fa318e048289b6d6225784ef Mon Sep 17 00:00:00 2001 From: Xin LI Date: Wed, 20 Jun 2012 21:10:38 +0000 Subject: [PATCH] Polish previous revision: if the fts_* routines have lstat()'ed the directory entry then use the struct stat from that instead of doing it again, and skip the rm_overwrite() call if fts_read() indicated that the entry couldn't be a regular file. Obtained from: OpenBSD MFC after: 1 week --- bin/rm/rm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 1f81885d52cc..6575a8de891e 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -301,10 +301,16 @@ rm_tree(char **argv) if (fflag) continue; /* FALLTHROUGH */ - default: + + case FTS_F: + case FTS_NSOK: if (Pflag) - if (!rm_overwrite(p->fts_accpath, NULL)) + if (!rm_overwrite(p->fts_accpath, p->fts_info == + FTS_NSOK ? NULL : p->fts_statp)) continue; + /* FALLTHROUGH */ + + default: rval = unlink(p->fts_accpath); if (rval == 0 || (fflag && errno == ENOENT)) { if (rval == 0 && vflag)