For the -delete option, emulate the behavior of "rm -f" when dealing with

user-immutable files.

Requested by: ache
This commit is contained in:
Peter Wemm 1996-10-05 18:21:05 +00:00
parent afb3e96f8a
commit 242ab807c6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18713

View File

@ -963,6 +963,13 @@ f_delete(plan, entry)
errx(1, "-delete: %s: relative path potentially not safe",
entry->fts_accpath);
/* Turn off user immutable bits if running as root */
if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
!(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
geteuid() == 0)
chflags(entry->fts_accpath,
entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
/* rmdir directories, unlink everything else */
if (S_ISDIR(entry->fts_statp->st_mode)) {
if (rmdir(entry->fts_accpath) < 0)