mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 05:52:27 +01:00
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
This commit is contained in:
parent
0f0e49422b
commit
c9795b4168
1 changed files with 92 additions and 53 deletions
|
@ -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;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
my_free(fname, MYF(MY_ALLOW_ZERO_PTR));
|
||||||
|
fname = NULL;
|
||||||
}
|
}
|
||||||
closedir(d);
|
|
||||||
if (error == 0) {
|
|
||||||
error = rmdir(dname);
|
|
||||||
if (error != 0)
|
|
||||||
error = errno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
error = errno;
|
|
||||||
}
|
}
|
||||||
|
closedir(d);
|
||||||
|
d = NULL;
|
||||||
|
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
my_free(fname, MYF(MY_ALLOW_ZERO_PTR));
|
||||||
|
fname = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
d = NULL;
|
||||||
|
|
||||||
|
error = rmdir(dname);
|
||||||
|
if (error != 0) {
|
||||||
|
error = errno;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue