]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: do not use tests_clear_dir
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 12 Apr 2011 13:22:35 +0000 (16:22 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mon, 18 Apr 2011 14:44:45 +0000 (17:44 +0300)
Do not use shared 'tests_clear_dir()' function which removes a directory
tree recursively, but instead use own implementation. This is because
I'm trying to make integck independend on the shared code because I
need this to do further improvements.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
tests/fs-tests/integrity/integck.c

index ed02b566333c73fe0ee5cda59ca05cce38ba906c..4806acd9df4f287cd2e6cbbb9f50e4495fa4e5a3 100644 (file)
@@ -1942,6 +1942,42 @@ static void create_test_data(void)
                do_an_operation();
 }
 
+/*
+ * Recursively remove a directory, just like "rm -rf" shell command.
+ */
+void rm_minus_rf_dir(const char *dir_name)
+{
+       DIR *dir;
+       struct dirent *entry;
+       char buf[PATH_MAX];
+
+       dir = opendir(dir_name);
+       CHECK(dir != NULL);
+       CHECK(getcwd(buf, PATH_MAX) != NULL);
+       CHECK(chdir(dir_name) == 0);
+
+       for (;;) {
+               errno = 0;
+               entry = readdir(dir);
+               if (!entry) {
+                       CHECK(errno == 0);
+                       break;
+               }
+
+               if (strcmp(entry->d_name, ".") &&
+                   strcmp(entry->d_name, "..")) {
+                       if (entry->d_type == DT_DIR)
+                               rm_minus_rf_dir(entry->d_name);
+                       else
+                               CHECK(unlink(entry->d_name) == 0);
+               }
+       }
+
+       CHECK(chdir(buf) == 0);
+       CHECK(closedir(dir) == 0);
+       CHECK(rmdir(dir_name) == 0);
+}
+
 static void update_test_data(void)
 {
        uint64_t i, n;
@@ -1977,19 +2013,17 @@ static int integck(void)
 {
        int64_t rpt;
 
-       /* Make our top directory */
-       if (chdir(fsinfo.test_dir) != -1) {
+       /* Create our top directory */
+       if (chdir(fsinfo.test_dir) == 0) {
                /* Remove it if it is already there */
-               tests_clear_dir(".");
-               CHECK(chdir("..") != -1);
-               CHECK(rmdir(fsinfo.test_dir) != -1);
+               CHECK(chdir("..") == 0);
+               rm_minus_rf_dir(fsinfo.test_dir);
        }
-       top_dir = dir_new(NULL, fsinfo.test_dir);
 
+       top_dir = dir_new(NULL, fsinfo.test_dir);
        if (!top_dir)
                return -1;
 
-       srand(getpid());
        create_test_data();
 
        if (!tests_fs_is_rootfs()) {
@@ -2018,8 +2052,7 @@ static int integck(void)
 
        /* Tidy up by removing everything */
        close_open_files();
-       tests_clear_dir(fsinfo.test_dir);
-       CHECK(rmdir(fsinfo.test_dir) != -1);
+       rm_minus_rf_dir(fsinfo.test_dir);
 
        return 0;
 }
@@ -2186,6 +2219,9 @@ int main(int argc, char *argv[])
        tests_file_system_mount_dir = (void *)fsinfo.mount_point;
        tests_file_system_type = (void *)fsinfo.fstype;
 
+       /* Seed the random generator with out PID */
+       srand(getpid());
+
        /* Do the actual test */
        ret = integck();
        if (ret)