Commit 4a15e3a6 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #1396

change rmall so that it handles the fact that .clean or .dirty files exist

git-svn-id: file:///svn/mysql/tokudb-engine/src@9146 c7de825b-a66e-492c-adef-691d508d4ae1
parent a05b5d48
...@@ -3783,68 +3783,107 @@ extern "C" { ...@@ -3783,68 +3783,107 @@ extern "C" {
static int rmall(const char *dname) { static int rmall(const char *dname) {
int error = 0; int error = 0;
DIR *d = opendir(dname);
char* fname = NULL; char* fname = NULL;
if (d) { struct dirent *dirent = NULL;;
struct dirent *dirent; DIR *d = opendir(dname);
while ((dirent = readdir(d)) != 0) {
if (0 == strcmp(dirent->d_name, ".") || 0 == strcmp(dirent->d_name, "..")) if (d == NULL) {
continue; error = errno;
fname = (char *)my_malloc(strlen(dname) + 1 + strlen(dirent->d_name) + 1, MYF(MY_WME)); goto cleanup;
sprintf(fname, "%s/%s", dname, dirent->d_name); }
if (dirent->d_type == DT_DIR) { //
error = rmall(fname); // we do two loops, first loop just removes all the .tokudb files
} // second loop removes extraneous files
else { //
while ((dirent = readdir(d)) != 0) {
if (0 == strcmp(dirent->d_name, ".") || 0 == strcmp(dirent->d_name, ".."))
continue;
fname = (char *)my_malloc(strlen(dname) + 1 + strlen(dirent->d_name) + 1, MYF(MY_WME));
sprintf(fname, "%s/%s", dname, dirent->d_name);
if (dirent->d_type == DT_DIR) {
error = rmall(fname);
if (error) { goto cleanup; }
}
else {
//
// if clause checks if the file is a .tokudb file
//
if (strlen(fname) >= strlen (ha_tokudb_ext) &&
strcmp(fname + (strlen(fname) - strlen(ha_tokudb_ext)), ha_tokudb_ext) == 0)
{
if (tokudb_debug & TOKUDB_DEBUG_OPEN) { if (tokudb_debug & TOKUDB_DEBUG_OPEN) {
TOKUDB_TRACE("removing:%s\n", fname); TOKUDB_TRACE("removing:%s\n", fname);
} }
// //
// if clause checks if the file is a .tokudb file // if this fails under low memory conditions, gracefully exit and return error
// user will be notified that something went wrong, and he will
// have to deal with it
// //
if (strlen(fname) >= strlen (ha_tokudb_ext) && DB* db = NULL;
strcmp(fname + (strlen(fname) - strlen(ha_tokudb_ext)), ha_tokudb_ext) == 0) error = db_create(&db, db_env, 0);
{ if (error) { goto cleanup; }
//
// if this fails under low memory conditions, gracefully exit and return error //
// user will be notified that something went wrong, and he will // it is ok to do db->remove on any .tokudb file, because any such
// have to deal with it // file was created with db->open
// //
DB* db = NULL; error = db->remove(db, fname, NULL, 0);
error = db_create(&db, db_env, 0); if (error) { goto cleanup; }
if (error) { }
break; else {
} continue;
//
// it is ok to do db->remove on any .tokudb file, because any such
// file was created with db->open
//
db->remove(db, fname, NULL, 0);
}
else {
//
// in case we have some file that is not .tokudb, we just delete it
//
error = unlink(fname);
if (error != 0) {
error = errno;
break;
}
}
my_free(fname, MYF(MY_ALLOW_ZERO_PTR));
fname = NULL;
} }
my_free(fname, MYF(MY_ALLOW_ZERO_PTR));
fname = NULL;
} }
closedir(d); }
if (error == 0) { closedir(d);
error = rmdir(dname); d = NULL;
if (error != 0)
fname = NULL;
d = opendir(dname);
if (d == NULL) {
error = errno;
goto cleanup;
}
//
// second loop to remove extraneous files
//
while ((dirent = readdir(d)) != 0) {
if (0 == strcmp(dirent->d_name, ".") || 0 == strcmp(dirent->d_name, ".."))
continue;
fname = (char *)my_malloc(strlen(dname) + 1 + strlen(dirent->d_name) + 1, MYF(MY_WME));
sprintf(fname, "%s/%s", dname, dirent->d_name);
if (dirent->d_type == DT_DIR) {
error = rmall(fname);
if (error) { goto cleanup; }
}
else {
if (tokudb_debug & TOKUDB_DEBUG_OPEN) {
TOKUDB_TRACE("removing:%s\n", fname);
}
//
// Now we are removing files that are not .tokudb, we just delete it
//
error = unlink(fname);
if (error != 0) {
error = errno; error = errno;
break;
}
my_free(fname, MYF(MY_ALLOW_ZERO_PTR));
fname = NULL;
} }
} }
else { closedir(d);
d = NULL;
error = rmdir(dname);
if (error != 0) {
error = errno; error = errno;
goto cleanup;
} }
cleanup:
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment