#At file:///C:/w/repo/mysql-5.1-telco-7.0-bug45402/ based on revid:jack@stripped
2940 jack andrews 2009-07-03
Bug #45402 Win32AsyncFile::rmrfReq can run an infinite loop
- added more remove() functions because AsyncFile does more
than just a rmrf on a directory. it
. deletes files
. the contents of the dir (like rm -rf dir/*)
modified:
storage/ndb/include/util/DirIterator.hpp
storage/ndb/src/common/util/DirIterator.cpp
=== modified file 'storage/ndb/include/util/DirIterator.hpp'
--- a/storage/ndb/include/util/DirIterator.hpp 2009-07-02 18:39:07 +0000
+++ b/storage/ndb/include/util/DirIterator.hpp 2009-07-03 12:55:00 +0000
@@ -57,7 +57,16 @@ public:
/*
Remove a directory and all it's subdirecrories
*/
-
int ndb_remove_dir_recursive(const char* name);
+/*
+ Remove all entries in directory
+*/
+int ndb_remove_dir_contents(const char* name);
+
+/*
+ a convenience function: tries unlink, then rmdir
+*/
+int ndb_remove_entry(const char* name);
+
#endif
=== modified file 'storage/ndb/src/common/util/DirIterator.cpp'
--- a/storage/ndb/src/common/util/DirIterator.cpp 2009-07-02 18:39:07 +0000
+++ b/storage/ndb/src/common/util/DirIterator.cpp 2009-07-03 12:55:00 +0000
@@ -252,6 +252,36 @@ static inline int rmdir(const char *s)
}
#endif
+int ndb_remove_dir_contents(const char* name)
+{
+ DirIterator di;
+ DirIterator::Entry entry;
+ int rv;
+ require(!(rv = di.open(name)));
+ int has_entries = (long)di.next_entry(entry);
+ if (!has_entries)
+ return 0;
+ di.close();
+ require(!di.open(name));
+ while ((name = di.next_entry(entry)))
+ { BaseString bs;
+ bs.assfmt("%s%s%s", di.path(), DIR_SEPARATOR, entry.name);
+ if (entry.type == DirIterator::Entry::ISDIR)
+ { if(ndb_remove_entry(bs.c_str()))
+ return ndb_remove_dir_recursive(bs.c_str());
+ } else
+ if (ndb_remove_entry(bs.c_str()))
+ return 1;
+ }
+ return 0;
+}
+int ndb_remove_entry(const char* name)
+{
+ if(!unlink(name) || !rmdir(name))
+ return 0;
+ return -1;
+}
+
int ndb_remove_dir_recursive(const char* dir) {
struct stat statbuf;
if(stat(dir,&statbuf)==-1 && errno==ENOENT)
@@ -304,11 +334,8 @@ inline int mkdirectory(const char *path)
}
#define TMP "tmp_dir_iterator"
-TAPTEST(DirIterator)
+int build_tree()
{
- struct stat statbuf;
- ndb_remove_dir_recursive(TMP);
- OK(stat(TMP,&statbuf)==-1 && errno==ENOENT);
OK(!mkdirectory(TMP));
fclose(fopen(TMP DIR_SEPARATOR "a","w"));
OK(!mkdirectory(TMP DIR_SEPARATOR "d"));
@@ -320,9 +347,28 @@ TAPTEST(DirIterator)
#ifndef _WIN32
OK(!symlink("/etc",TMP "/d/symlink"));
#endif
-
+ return 0;
+}
+int check_gone(const char *file)
+{
+ struct stat statbuf;
+ OK(stat(file,&statbuf)==-1 && errno==ENOENT);
+ return 0;
+}
+TAPTEST(DirIterator)
+{
+ struct stat statbuf;
+ ndb_remove_dir_recursive(TMP);
+ check_gone(TMP);
+ build_tree();
OK(!ndb_remove_dir_recursive(TMP));
OK(stat(TMP,&statbuf)==-1 && errno==ENOENT);
+ check_gone(TMP);
+ build_tree();
+ OK(!ndb_remove_dir_contents(TMP));
+ OK(!mkdirectory(TMP DIR_SEPARATOR "a"));
+ ndb_remove_dir_contents(TMP);
+ OK(!rmdir(TMP));
return 1;
}
#endif
Attachment: [text/bzr-bundle] bzr/jack@sun.com-20090703125500-rimmj4hpsl2r2vcd.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.0 branch (jack:2940) Bug#45402 | jack andrews | 3 Jul |