bin/187264: rm command: rm -r file1 file2 "" does not remove existing files or directories

John Wolfe jlw at xinuos.com
Tue Mar 4 21:50:01 UTC 2014


>Number:         187264
>Category:       bin
>Synopsis:       rm command: rm -r file1 file2 "" does not remove existing files or directories
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 04 21:50:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     John Wolfe
>Release:        FreeBSD 9.2   (PC-BSD 9.2)
>Organization:
Xinuos, Inc.
>Environment:
FreeBSD sapphire.nj.sco.com 9.2-RELEASE-p12 FreeBSD 9.2-RELEASE-p12 #0: Thu Jan 16 21:12:30 UTC 2014     root at amd64-builder.pcbsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
When the gmake/make clean target contains a command of the form

   rm -rf "a.out" "$(DSYM)"  main.o main.d

the  command fails to remove any of the existing files if DSYM is null.
The '-f' option hides the error associated with the zero length file name, but gives no indication that, in fact, NO files/directories have been removed.


>How-To-Repeat:
Use the following script to see the problem

rm.bug.sh:
======================
#! /bin/sh
set -x

cat  > file_1 << !EOF
12345
How no brown cow
!EOF
cp file_1 file_2
cp file_1 file_3

# The following command should remove file_[123], but does not.
# The '-r' implies the '-d' option - attempt to remove directories 
# as well as other types of files.    The "" results in an error 
# when treated as a possible directory.
#
#  $ rm -r ""
#  rm: fts_open: No such file or directory
#
# which is a valid error, but none of the arguments are removed.
# 
# When the following command is run without the '-r', all three 
# files are removed.


rm -r "file_1" "" file_[23]

ls -l

# Yet a "rm -r " with a non-existant file in the list, will remove 
# all existing files.

rm -r "file_1" "xxx" file_2

ls -l

>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list