svn commit: samba r20558 - in branches: SAMBA_3_0/source/smbd SAMBA_3_0_24/source/smbd

jra at samba.org jra at samba.org
Fri Jan 5 17:42:55 GMT 2007


Author: jra
Date: 2007-01-05 17:42:54 +0000 (Fri, 05 Jan 2007)
New Revision: 20558

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20558

Log:
Refactor rmdir_internals to use early termination rather
than lots of indented code. Change recursive_rmdir()
to return the smbd standards of True on success, False
on fail (it was doing the reverse, which was very confusing).
Jeremy.

Modified:
   branches/SAMBA_3_0/source/smbd/reply.c
   branches/SAMBA_3_0_24/source/smbd/reply.c


Changeset:
Modified: branches/SAMBA_3_0/source/smbd/reply.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/reply.c	2007-01-05 17:40:43 UTC (rev 20557)
+++ branches/SAMBA_3_0/source/smbd/reply.c	2007-01-05 17:42:54 UTC (rev 20558)
@@ -3822,18 +3822,18 @@
 
 /****************************************************************************
  Static function used by reply_rmdir to delete an entire directory
- tree recursively. Return False on ok, True on fail.
+ tree recursively. Return True on ok, False on fail.
 ****************************************************************************/
 
 static BOOL recursive_rmdir(connection_struct *conn, char *directory)
 {
 	const char *dname = NULL;
-	BOOL ret = False;
+	BOOL ret = True;
 	long offset = 0;
 	struct smb_Dir *dir_hnd = OpenDir(conn, directory, NULL, 0);
 
 	if(dir_hnd == NULL)
-		return True;
+		return False;
 
 	while((dname = ReadDirName(dir_hnd, &offset))) {
 		pstring fullname;
@@ -3848,7 +3848,7 @@
 		/* Construct the full name. */
 		if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
 			errno = ENOMEM;
-			ret = True;
+			ret = False;
 			break;
 		}
 
@@ -3857,21 +3857,21 @@
 		pstrcat(fullname, dname);
 
 		if(SMB_VFS_LSTAT(conn,fullname, &st) != 0) {
-			ret = True;
+			ret = False;
 			break;
 		}
 
 		if(st.st_mode & S_IFDIR) {
-			if(recursive_rmdir(conn, fullname)!=0) {
-				ret = True;
+			if(!recursive_rmdir(conn, fullname)) {
+				ret = False;
 				break;
 			}
 			if(SMB_VFS_RMDIR(conn,fullname) != 0) {
-				ret = True;
+				ret = False;
 				break;
 			}
 		} else if(SMB_VFS_UNLINK(conn,fullname) != 0) {
-			ret = True;
+			ret = False;
 			break;
 		}
 	}
@@ -3896,66 +3896,67 @@
 		 * retry. If we fail to delete any of them (and we *don't*
 		 * do a recursive delete) then fail the rmdir.
 		 */
-		BOOL all_veto_files = True;
 		const char *dname;
+		long dirpos = 0;
 		struct smb_Dir *dir_hnd = OpenDir(conn, directory, NULL, 0);
 
-		if(dir_hnd != NULL) {
-			long dirpos = 0;
-			while ((dname = ReadDirName(dir_hnd,&dirpos))) {
-				if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
-					continue;
-				if (!is_visible_file(conn, directory, dname, &st, False))
-					continue;
-				if(!IS_VETO_PATH(conn, dname)) {
-					all_veto_files = False;
-					break;
-				}
+		if(dir_hnd == NULL) {
+			errno = ENOTEMPTY;
+			goto err;
+		}
+
+		while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+			if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
+				continue;
+			if (!is_visible_file(conn, directory, dname, &st, False))
+				continue;
+			if(!IS_VETO_PATH(conn, dname)) {
+				CloseDir(dir_hnd);
+				errno = ENOTEMPTY;
+				goto err;
 			}
+		}
 
-			if(all_veto_files) {
-				RewindDir(dir_hnd,&dirpos);
-				while ((dname = ReadDirName(dir_hnd,&dirpos))) {
-					pstring fullname;
+		/* We only have veto files/directories. Recursive delete. */
 
-					if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
-						continue;
-					if (!is_visible_file(conn, directory, dname, &st, False))
-						continue;
+		RewindDir(dir_hnd,&dirpos);
+		while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+			pstring fullname;
 
-					/* Construct the full name. */
-					if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
-						errno = ENOMEM;
-						break;
-					}
+			if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
+				continue;
+			if (!is_visible_file(conn, directory, dname, &st, False))
+				continue;
 
-					pstrcpy(fullname, directory);
-					pstrcat(fullname, "/");
-					pstrcat(fullname, dname);
+			/* Construct the full name. */
+			if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
+				errno = ENOMEM;
+				break;
+			}
+
+			pstrcpy(fullname, directory);
+			pstrcat(fullname, "/");
+			pstrcat(fullname, dname);
                      
-					if(SMB_VFS_LSTAT(conn,fullname, &st) != 0)
+			if(SMB_VFS_LSTAT(conn,fullname, &st) != 0)
+				break;
+			if(st.st_mode & S_IFDIR) {
+				if(lp_recursive_veto_delete(SNUM(conn))) {
+					if(!recursive_rmdir(conn, fullname))
 						break;
-					if(st.st_mode & S_IFDIR) {
-						if(lp_recursive_veto_delete(SNUM(conn))) {
-							if(recursive_rmdir(conn, fullname) != 0)
-								break;
-						}
-						if(SMB_VFS_RMDIR(conn,fullname) != 0)
-							break;
-					} else if(SMB_VFS_UNLINK(conn,fullname) != 0)
-						break;
 				}
-				CloseDir(dir_hnd);
-				/* Retry the rmdir */
-				ok = (SMB_VFS_RMDIR(conn,directory) == 0);
-			} else {
-				CloseDir(dir_hnd);
-			}
-		} else {
-			errno = ENOTEMPTY;
+				if(SMB_VFS_RMDIR(conn,fullname) != 0)
+					break;
+			} else if(SMB_VFS_UNLINK(conn,fullname) != 0)
+				break;
 		}
+		CloseDir(dir_hnd);
+		/* Retry the rmdir */
+		ok = (SMB_VFS_RMDIR(conn,directory) == 0);
 	}
 
+  err:
+
 	if (!ok) {
 		DEBUG(3,("rmdir_internals: couldn't remove directory %s : "
 			 "%s\n", directory,strerror(errno)));

Modified: branches/SAMBA_3_0_24/source/smbd/reply.c
===================================================================
--- branches/SAMBA_3_0_24/source/smbd/reply.c	2007-01-05 17:40:43 UTC (rev 20557)
+++ branches/SAMBA_3_0_24/source/smbd/reply.c	2007-01-05 17:42:54 UTC (rev 20558)
@@ -3802,18 +3802,18 @@
 
 /****************************************************************************
  Static function used by reply_rmdir to delete an entire directory
- tree recursively. Return False on ok, True on fail.
+ tree recursively. Return True on ok, False on fail.
 ****************************************************************************/
 
 static BOOL recursive_rmdir(connection_struct *conn, char *directory)
 {
 	const char *dname = NULL;
-	BOOL ret = False;
+	BOOL ret = True;
 	long offset = 0;
 	struct smb_Dir *dir_hnd = OpenDir(conn, directory, NULL, 0);
 
 	if(dir_hnd == NULL)
-		return True;
+		return False;
 
 	while((dname = ReadDirName(dir_hnd, &offset))) {
 		pstring fullname;
@@ -3828,7 +3828,7 @@
 		/* Construct the full name. */
 		if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
 			errno = ENOMEM;
-			ret = True;
+			ret = False;
 			break;
 		}
 
@@ -3837,21 +3837,21 @@
 		pstrcat(fullname, dname);
 
 		if(SMB_VFS_LSTAT(conn,fullname, &st) != 0) {
-			ret = True;
+			ret = False;
 			break;
 		}
 
 		if(st.st_mode & S_IFDIR) {
-			if(recursive_rmdir(conn, fullname)!=0) {
-				ret = True;
+			if(!recursive_rmdir(conn, fullname)) {
+				ret = False;
 				break;
 			}
 			if(SMB_VFS_RMDIR(conn,fullname) != 0) {
-				ret = True;
+				ret = False;
 				break;
 			}
 		} else if(SMB_VFS_UNLINK(conn,fullname) != 0) {
-			ret = True;
+			ret = False;
 			break;
 		}
 	}
@@ -3876,66 +3876,67 @@
 		 * retry. If we fail to delete any of them (and we *don't*
 		 * do a recursive delete) then fail the rmdir.
 		 */
-		BOOL all_veto_files = True;
 		const char *dname;
+		long dirpos = 0;
 		struct smb_Dir *dir_hnd = OpenDir(conn, directory, NULL, 0);
 
-		if(dir_hnd != NULL) {
-			long dirpos = 0;
-			while ((dname = ReadDirName(dir_hnd,&dirpos))) {
-				if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
-					continue;
-				if (!is_visible_file(conn, directory, dname, &st, False))
-					continue;
-				if(!IS_VETO_PATH(conn, dname)) {
-					all_veto_files = False;
-					break;
-				}
+		if(dir_hnd == NULL) {
+			errno = ENOTEMPTY;
+			goto err;
+		}
+
+		while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+			if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
+				continue;
+			if (!is_visible_file(conn, directory, dname, &st, False))
+				continue;
+			if(!IS_VETO_PATH(conn, dname)) {
+				CloseDir(dir_hnd);
+				errno = ENOTEMPTY;
+				goto err;
 			}
+		}
 
-			if(all_veto_files) {
-				RewindDir(dir_hnd,&dirpos);
-				while ((dname = ReadDirName(dir_hnd,&dirpos))) {
-					pstring fullname;
+		/* We only have veto files/directories. Recursive delete. */
 
-					if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
-						continue;
-					if (!is_visible_file(conn, directory, dname, &st, False))
-						continue;
+		RewindDir(dir_hnd,&dirpos);
+		while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+			pstring fullname;
 
-					/* Construct the full name. */
-					if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
-						errno = ENOMEM;
-						break;
-					}
+			if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
+				continue;
+			if (!is_visible_file(conn, directory, dname, &st, False))
+				continue;
 
-					pstrcpy(fullname, directory);
-					pstrcat(fullname, "/");
-					pstrcat(fullname, dname);
-                     
-					if(SMB_VFS_LSTAT(conn,fullname, &st) != 0)
+			/* Construct the full name. */
+			if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
+				errno = ENOMEM;
+				break;
+			}
+
+			pstrcpy(fullname, directory);
+			pstrcat(fullname, "/");
+			pstrcat(fullname, dname);
+                   
+			if(SMB_VFS_LSTAT(conn,fullname, &st) != 0)
+				break;
+			if(st.st_mode & S_IFDIR) {
+				if(lp_recursive_veto_delete(SNUM(conn))) {
+					if(!recursive_rmdir(conn, fullname))
 						break;
-					if(st.st_mode & S_IFDIR) {
-						if(lp_recursive_veto_delete(SNUM(conn))) {
-							if(recursive_rmdir(conn, fullname) != 0)
-								break;
-						}
-						if(SMB_VFS_RMDIR(conn,fullname) != 0)
-							break;
-					} else if(SMB_VFS_UNLINK(conn,fullname) != 0)
-						break;
 				}
-				CloseDir(dir_hnd);
-				/* Retry the rmdir */
-				ok = (SMB_VFS_RMDIR(conn,directory) == 0);
-			} else {
-				CloseDir(dir_hnd);
-			}
-		} else {
-			errno = ENOTEMPTY;
+				if(SMB_VFS_RMDIR(conn,fullname) != 0)
+					break;
+			} else if(SMB_VFS_UNLINK(conn,fullname) != 0)
+				break;
 		}
+		CloseDir(dir_hnd);
+		/* Retry the rmdir */
+		ok = (SMB_VFS_RMDIR(conn,directory) == 0);
 	}
 
+  err:
+
 	if (!ok) {
 		DEBUG(3,("rmdir_internals: couldn't remove directory %s : "
 			 "%s\n", directory,strerror(errno)));



More information about the samba-cvs mailing list