svn commit: samba r8282 - in branches/SAMBA_4_0/source/smbd: .

tridge at samba.org tridge at samba.org
Sun Jul 10 08:06:28 GMT 2005


Author: tridge
Date: 2005-07-10 08:06:28 +0000 (Sun, 10 Jul 2005)
New Revision: 8282

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

Log:
make the deletion of the smbd.tmp directory recursive. This cleans up the messaging
directory

Modified:
   branches/SAMBA_4_0/source/smbd/server.c


Changeset:
Modified: branches/SAMBA_4_0/source/smbd/server.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/server.c	2005-07-10 06:51:00 UTC (rev 8281)
+++ branches/SAMBA_4_0/source/smbd/server.c	2005-07-10 08:06:28 UTC (rev 8282)
@@ -33,66 +33,61 @@
 
 
 /*
-  cleanup temporary files. This is the new alternative to
-  TDB_CLEAR_IF_FIRST. Unfortunately TDB_CLEAR_IF_FIRST is not
-  efficient on unix systems due to the lack of scaling of the byte
-  range locking system. So instead of putting the burden on tdb to
-  cleanup tmp files, this function deletes them. 
+  recursively delete a directory tree
 */
-static void cleanup_tmp_files(void)
+static void recursive_delete(const char *path)
 {
-	char *path;
 	DIR *dir;
 	struct dirent *de;
-	TALLOC_CTX *mem_ctx = talloc_new(NULL);
 
-	path = smbd_tmp_path(mem_ctx, NULL);
-
 	dir = opendir(path);
 	if (!dir) {
-		talloc_free(mem_ctx);
 		return;
 	}
 
 	for (de=readdir(dir);de;de=readdir(dir)) {
-		/*
-		 * Don't try to delete . and ..
-		 */
-		if (strcmp(de->d_name, ".") != 0 &&
-		    strcmp(de->d_name, "..") != 0) {
-		    char *fname = talloc_asprintf(mem_ctx, "%s/%s", path, de->d_name);
-		    int ret = unlink(fname);
-		    if (ret == -1 &&
-		        errno != ENOENT &&
-			errno != EPERM &&
-		        errno != EISDIR) {
-			    DEBUG(0,("Unabled to delete '%s' - %s\n", 
-				      fname, strerror(errno)));
-			    smb_panic("unable to cleanup tmp files");
-		    }
-		    if (ret == -1 &&
-			errno == EPERM) {
-			/*
-			 * If it is a dir, don't complain
-			 * NOTE! The test will only happen if we have
-			 * sys/stat.h, otherwise we will always error out
-			 */
-#ifdef HAVE_SYS_STAT_H
-			struct stat sb;
-			if (stat(fname, &sb) != -1 &&
-			    !S_ISDIR(sb.st_mode))
-#endif
-			{
-			     DEBUG(0,("Unable to delete '%s' - %s\n",
-				      fname, strerror(errno)));
-			     smb_panic("unable to cleanup tmp files");
-			}
-		    }
-		    talloc_free(fname);
+		char *fname;
+		struct stat st;
+
+		if (strcmp(de->d_name, ".") == 0 ||
+		    strcmp(de->d_name, "..") == 0) {
+			continue;
 		}
+
+		fname = talloc_asprintf(path, "%s/%s", path, de->d_name);
+		if (stat(fname, &st) != 0) {
+			continue;
+		}
+		if (S_ISDIR(st.st_mode)) {
+			recursive_delete(fname);
+			talloc_free(fname);
+			continue;
+		}
+		if (unlink(fname) != 0) {
+			DEBUG(0,("Unabled to delete '%s' - %s\n", 
+				 fname, strerror(errno)));
+			smb_panic("unable to cleanup tmp files");
+		}
+		talloc_free(fname);
 	}
 	closedir(dir);
+}
 
+/*
+  cleanup temporary files. This is the new alternative to
+  TDB_CLEAR_IF_FIRST. Unfortunately TDB_CLEAR_IF_FIRST is not
+  efficient on unix systems due to the lack of scaling of the byte
+  range locking system. So instead of putting the burden on tdb to
+  cleanup tmp files, this function deletes them. 
+*/
+static void cleanup_tmp_files(void)
+{
+	char *path;
+	TALLOC_CTX *mem_ctx = talloc_new(NULL);
+
+	path = smbd_tmp_path(mem_ctx, NULL);
+
+	recursive_delete(path);
 	talloc_free(mem_ctx);
 }
 



More information about the samba-cvs mailing list