summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-07-06 15:22:31 +1000
committerMatthieu Patou <mat@samba.org>2010-10-11 13:46:21 +0000
commit74ed86c4e3d997a283e1ac03237ece9397242d81 (patch)
tree3ee114595e3b3917f2af88007387983ac679d69f /lib
parent13ba3464c08208a1dc00a3edb55281b15ddd44a7 (diff)
downloadsamba-74ed86c4e3d997a283e1ac03237ece9397242d81.tar.gz
samba-74ed86c4e3d997a283e1ac03237ece9397242d81.tar.bz2
samba-74ed86c4e3d997a283e1ac03237ece9397242d81.zip
lib/torture: Add function to clean up the output directory
This helps to avoid leaving 85MB of provision around for every NET-API-BECOME-DC test. Andrew Bartlett Signed-off-by: Matthieu Patou <mat@matws.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/torture/torture.c66
-rw-r--r--lib/torture/torture.h1
2 files changed, 66 insertions, 1 deletions
diff --git a/lib/torture/torture.c b/lib/torture/torture.c
index 74dfce19db..ead89cdd5e 100644
--- a/lib/torture/torture.c
+++ b/lib/torture/torture.c
@@ -23,6 +23,7 @@
#include "../lib/util/dlinklist.h"
#include "param/param.h"
#include "system/filesys.h"
+#include "system/dir.h"
struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops)
@@ -75,7 +76,7 @@ struct torture_context *torture_context_child(struct torture_context *parent)
}
/**
- create a temporary directory.
+ create a temporary directory under the output dir
*/
_PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx,
const char *prefix, char **tempdir)
@@ -93,6 +94,69 @@ _PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx,
return NT_STATUS_OK;
}
+static int local_deltree(const char *path)
+{
+ int ret;
+ struct dirent *dirent;
+ DIR *dir = opendir(path);
+ if (!dir) {
+ char *error = talloc_asprintf(NULL, "Could not open directory %s", path);
+ perror(error);
+ talloc_free(error);
+ return -1;
+ }
+ while ((dirent = readdir(dir))) {
+ char *name;
+ if ((strcmp(dirent->d_name, ".") == 0) || (strcmp(dirent->d_name, "..") == 0)) {
+ continue;
+ }
+ name = talloc_asprintf(NULL, "%s/%s", path,
+ dirent->d_name);
+ if (name == NULL) {
+ closedir(dir);
+ return -1;
+ }
+ ret = remove(name);
+ if (ret == 0) {
+ talloc_free(name);
+ continue;
+ }
+
+ if (errno == ENOTEMPTY) {
+ ret = local_deltree(name);
+ if (ret == 0) {
+ ret = remove(name);
+ }
+ }
+ talloc_free(name);
+ if (ret != 0) {
+ char *error = talloc_asprintf(NULL, "Could not remove %s", path);
+ perror(error);
+ talloc_free(error);
+ break;
+ }
+ }
+ closedir(dir);
+ return ret;
+}
+
+_PUBLIC_ NTSTATUS torture_deltree_outputdir(struct torture_context *tctx)
+{
+ SMB_ASSERT(tctx->outputdir != NULL);
+ if ((strcmp(tctx->outputdir, "/") == 0)
+ || (strcmp(tctx->outputdir, "") == 0)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (local_deltree(tctx->outputdir) == -1) {
+ if (errno != 0) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ return NT_STATUS_OK;
+}
+
/**
* Comment on the status/progress of a test
*/
diff --git a/lib/torture/torture.h b/lib/torture/torture.h
index 01947e773d..605ba341eb 100644
--- a/lib/torture/torture.h
+++ b/lib/torture/torture.h
@@ -488,6 +488,7 @@ unsigned long torture_setting_ulong(struct torture_context *test,
NTSTATUS torture_temp_dir(struct torture_context *tctx,
const char *prefix,
char **tempdir);
+NTSTATUS torture_deltree_outputdir(struct torture_context *tctx);
struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
const char *name,