[501] in testers
delete patch
daemon@ATHENA.MIT.EDU (daemon@ATHENA.MIT.EDU)
Fri Dec 15 04:44:24 1989
Date: Fri, 15 Dec 89 04:43:42 -0500
From: Jonathan I. Kamens <jik@PIT-MANAGER.MIT.EDU>
To: testers@ATHENA.MIT.EDU
Files affected: util.h
delete.c
undelete.c
pattern.c
Priority: Low. This patch does not have to make it into the
release. This patch will not affect the operation of
delete, undelete, lsdel, expunge or purge on Project
Athena workstations currently in the field.
Bugs fixed: (1) I assumed in several places that doing an opendir
of the string "" would result in the opening of the
current working directory. In some variants in Unix
(most notably in AIX, on which jfc discovered this
bug), this is not the case.
(2) My failure to initialize a status variable at the
start of a procedure might result in an incorrect
error message in _very_ strange situations. I don't
foresee it ever happening, but the compiler
complained, so I fixed it.
jik
*** /tmp/,RCSt1007240 Fri Dec 15 04:37:44 1989
--- util.h Fri Dec 15 04:37:11 1989
***************
*** 33,35 ****
--- 33,39 ----
(*(A + 2) == '\0'))))
#define is_deleted(A) ((*A == '.') && (*(A + 1) == '#'))
+
+ /* It would be BAD to pass something with a ++ anywhere near it into */
+ /* this macro! */
+ #define Opendir(dir) opendir(*(dir) ? (dir) : ".")
*** /tmp/,RCSt1007247 Fri Dec 15 04:38:39 1989
--- delete.c Fri Dec 15 04:25:39 1989
***************
*** 299,305 ****
DIR *dirp;
struct direct *dp;
! dirp = opendir(filename);
if (! dirp) {
set_error(errno);
error(filename);
--- 299,305 ----
DIR *dirp;
struct direct *dp;
! dirp = Opendir(filename);
if (! dirp) {
set_error(errno);
error(filename);
***************
*** 331,337 ****
struct direct *dp;
int status = 0;
char newfile[MAXPATHLEN];
! int retval;
if (interactive && recursed) {
printf("%s: remove directory %s? ", whoami, filename);
--- 331,337 ----
struct direct *dp;
int status = 0;
char newfile[MAXPATHLEN];
! int retval = 0;
if (interactive && recursed) {
printf("%s: remove directory %s? ", whoami, filename);
***************
*** 340,346 ****
return error_code;
}
}
! dirp = opendir(filename);
if (! dirp) {
if (emulate_rm && (! force))
fprintf(stderr, "%s: %s not changed\n", whoami, filename);
--- 340,346 ----
return error_code;
}
}
! dirp = Opendir(filename);
if (! dirp) {
if (emulate_rm && (! force))
fprintf(stderr, "%s: %s not changed\n", whoami, filename);
***************
*** 494,500 ****
}
if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) {
! dirp = opendir(filename);
if (! dirp) {
set_error(errno);
error(filename);
--- 494,500 ----
}
if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) {
! dirp = Opendir(filename);
if (! dirp) {
set_error(errno);
error(filename);
*** /tmp/,RCSt1007247 Fri Dec 15 04:38:43 1989
--- undelete.c Fri Dec 15 04:23:53 1989
***************
*** 533,539 ****
}
if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) {
! dirp = opendir(filename);
if (! dirp) {
set_error(errno);
error(filename);
--- 533,539 ----
}
if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) {
! dirp = Opendir(filename);
if (! dirp) {
set_error(errno);
error(filename);
*** /tmp/,RCSt1007247 Fri Dec 15 04:38:47 1989
--- pattern.c Fri Dec 15 04:23:43 1989
***************
*** 358,364 ****
* base = "" or "/",
* name = name or name + 1
* initialze found and num_found
! * dirp = opendir(base)
* first = firstpart(name, rest) (assigns rest as side-effect)
* if (! *first) {
* add string to list if appropriate
--- 358,364 ----
* base = "" or "/",
* name = name or name + 1
* initialze found and num_found
! * dirp = Opendir(base)
* first = firstpart(name, rest) (assigns rest as side-effect)
* if (! *first) {
* add string to list if appropriate
***************
*** 433,439 ****
}
*num_found = 0;
! dirp = opendir(base);
if (! dirp) {
set_error(errno);
error(base);
--- 433,439 ----
}
*num_found = 0;
! dirp = Opendir(base);
if (! dirp) {
set_error(errno);
error(base);
***************
*** 518,524 ****
continue;
}
! dirp = opendir(base);
if (! dirp) {
if (errno != ENOTDIR) {
set_error(errno);
--- 518,524 ----
continue;
}
! dirp = Opendir(base);
if (! dirp) {
if (errno != ENOTDIR) {
set_error(errno);
***************
*** 584,590 ****
* start:
* initialze found and num_found
* strcopy(base, name)
! * dirp = opendir(base)
* check if we just opened a deleted symlink and return if we did
* check RECURS options and set FIND options as appropriate
*
--- 584,590 ----
* start:
* initialze found and num_found
* strcopy(base, name)
! * dirp = Opendir(base)
* check if we just opened a deleted symlink and return if we did
* check RECURS options and set FIND options as appropriate
*
***************
*** 678,684 ****
return 0;
}
! dirp = opendir(base);
if (! dirp) {
/* If the problem is that it isn't a directory, just return */
/* with zero matches -- the file exists, but cannot be */
--- 678,684 ----
return 0;
}
! dirp = Opendir(base);
if (! dirp) {
/* If the problem is that it isn't a directory, just return */
/* with zero matches -- the file exists, but cannot be */
***************
*** 770,784 ****
(void) strcpy(base, append(base, dp->d_name));
/*
! * Originally, I did an opendir() right at the start and
! * then only checked things if the opendir resulted in an
* error. However, this is inefficient, because the
! * opendir() procedure works by first calling open() on the
* file, and *then* calling fstat on the file descriptor
* that is returned. since most of the time we will be
* trying to open things that are not directory, it is much
* more effecient to do the stat first here and to do the
! * opendir only if the stat results are satisfactory.
*/
use_stat = (options & FOLLW_LINKS) && (! is_deleted(lastpart(base)));
if (use_stat)
--- 770,784 ----
(void) strcpy(base, append(base, dp->d_name));
/*
! * Originally, I did an Opendir() right at the start and
! * then only checked things if the Opendir resulted in an
* error. However, this is inefficient, because the
! * Opendir() procedure works by first calling open() on the
* file, and *then* calling fstat on the file descriptor
* that is returned. since most of the time we will be
* trying to open things that are not directory, it is much
* more effecient to do the stat first here and to do the
! * Opendir only if the stat results are satisfactory.
*/
use_stat = (options & FOLLW_LINKS) && (! is_deleted(lastpart(base)));
if (use_stat)
***************
*** 800,806 ****
}
/* Actually try to open it. */
! dirp = opendir(base);
if (! dirp) {
set_error(errno);
error(base);
--- 800,806 ----
}
/* Actually try to open it. */
! dirp = Opendir(base);
if (! dirp) {
set_error(errno);
error(base);