Subject: Re: rm
To: None <current-users@netbsd.org>
From: Zdenek Salvet <salvet@nyx.dcs.muni.cz>
List: current-users
Date: 10/31/1994 20:56:41
> I do agree to some extent, however, in this case, I think it is more a
> matter of consistancy, not with the standard, but internal consistancy. It
> was pointed out in an earlier post that rm(1) works one way, rmdir(1) works
> another, both on the same type of data. SYSV once upon a time treated the
> trailing '/' the same as BSD still does, but at some point some person or
> people decided it made more sense. This does not necessarily mean BSD has
> to do this, or even necessarily should. However, just because BSD has
> always done something a certain thing a certain way, does not mean that
> this should also be blindly followed forever, standard or no.

  There is simply bug in /bin/rm ; rmdir has code to handle trailing slashes.
  Fix:
*** /usr/src/bin/rm/rm.c	Mon Oct 31 20:32:32 1994
--- /home/salvet/tmp/soft/rm-fixed.c	Mon Oct 31 20:18:10 1994
***************
*** 120,125 ****
--- 120,138 ----
  	exit(retval);
  }
  
+ static int aux_rmdir(const char *pathname)
+ {
+ 	if (pathname) {
+                 register char *slash;
+ 
+                 /* delete trailing slashes */
+                 slash = strrchr(pathname, '\0');
+                 while (--slash > pathname && *slash == '/')
+                         *slash = '\0';
+ 	}
+ 	return rmdir(pathname);
+ }
+     
  void
  rmtree(argv)
  	char **argv;
***************
*** 189,201 ****
  		 * message unless the remove fails.
  		 */
  		if (p->fts_info == FTS_DP || p->fts_info == FTS_DNR) {
! 			if (!rmdir(p->fts_accpath) || fflag && errno == ENOENT) 
  				continue;
  		} else {
  			if (!unlink(p->fts_accpath) || fflag && errno == ENOENT)
  				continue;
  		}
  		error(p->fts_path, errno);
  	}
  }
  
--- 202,214 ----
  		 * message unless the remove fails.
  		 */
  		if (p->fts_info == FTS_DP || p->fts_info == FTS_DNR) {
! 			if (!aux_rmdir(p->fts_accpath) || fflag && errno == ENOENT) 
  				continue;
  		} else {
  			if (!unlink(p->fts_accpath) || fflag && errno == ENOENT)
  				continue;
  		}
  		error(p->fts_path, errno);
  	}
  }
  
***************
*** 238,244 ****
  		/*
  		 * rmdir() directories, unlink() files...
  		 */
! 		if ((S_ISDIR(sb.st_mode) ? rmdir(f) : unlink(f))) {
  			error(f, errno);
  		}
  	}
--- 251,257 ----
  		/*
  		 * rmdir() directories, unlink() files...
  		 */
! 		if ((S_ISDIR(sb.st_mode) ? aux_rmdir(f) : unlink(f))) {
  			error(f, errno);
  		}
  	}

Zdenek Salvet
salvet@nyx.dcs.muni.cz