* libmisc/copydir.c (remove_tree): As we always use remove_tree

followed by rmdir to remove the directory itself, delete also the
	root directory in remove_tree.
	* src/userdel.c, src/usermod.c: Do not call rmdir after
	remove_tree.
This commit is contained in:
nekral-guest 2008-05-24 15:35:15 +00:00
parent 9c41a8ad38
commit 6124b59aff
4 changed files with 24 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2008-05-24 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/copydir.c (remove_tree): As we always use remove_tree
followed by rmdir to remove the directory itself, delete also the
root directory in remove_tree.
* src/userdel.c, src/usermod.c: Do not call rmdir after
remove_tree.
2008-05-24 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/copydir.c (remove_tree): Make sure unlink is successful

View File

@ -557,10 +557,11 @@ static int copy_file (const char *src, const char *dst,
}
/*
* remove_tree - remove files in a directory tree
* remove_tree - delete a directory tree
*
* remove_tree() walks a directory tree and deletes all the files
* and directories.
* At the end, it deletes the root directory itself.
*/
int remove_tree (const char *root)
@ -617,20 +618,17 @@ int remove_tree (const char *root)
}
if (S_ISDIR (sb.st_mode)) {
/*
* Recursively delete this directory.
*/
if (remove_tree (new_name) != 0) {
err = -1;
break;
}
if (rmdir (new_name) != 0) {
err = -1;
break;
}
} else {
/*
* Delete the file.
*/
if (unlink (new_name) != 0) {
err = -1;
break;
@ -639,6 +637,12 @@ int remove_tree (const char *root)
}
(void) closedir (dir);
if (0 == err) {
if (rmdir (root) != 0) {
err = -1;
}
}
return err;
}

View File

@ -794,8 +794,7 @@ int main (int argc, char **argv)
#endif
if (rflg) {
if (remove_tree (user_home)
|| rmdir (user_home)) {
if (remove_tree (user_home) != 0) {
fprintf (stderr,
_("%s: error removing directory %s\n"),
Prog, user_home);

View File

@ -1288,12 +1288,12 @@ static void move_home (void)
if (copy_tree (user_home, user_newhome,
uflg ? (long int)user_newid : -1,
gflg ? (long int)user_newgid : -1) == 0) {
if (remove_tree (user_home) != 0 ||
rmdir (user_home) != 0)
if (remove_tree (user_home) != 0) {
fprintf (stderr,
_
("%s: warning: failed to completely remove old home directory %s"),
Prog, user_home);
}
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK,
Prog,
@ -1304,8 +1304,9 @@ static void move_home (void)
return;
}
/* TODO: do some cleanup if the copy
* was started */
(void) remove_tree (user_newhome);
(void) rmdir (user_newhome);
}
fprintf (stderr,
_