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) {
|
||||
int error = 0;
|
||||
DIR *d = opendir(dname);
|
||||
char* fname = NULL;
|
||||
if (d) {
|
||||
struct dirent *dirent;
|
||||
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);
|
||||
}
|
||||
else {
|
||||
struct dirent *dirent = NULL;;
|
||||
DIR *d = opendir(dname);
|
||||
|
||||
if (d == NULL) {
|
||||
error = errno;
|
||||
goto cleanup;
|
||||
}
|
||||
//
|
||||
// we do two loops, first loop just removes all the .tokudb files
|
||||
// second loop removes 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 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) {
|
||||
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) &&
|
||||
strcmp(fname + (strlen(fname) - strlen(ha_tokudb_ext)), ha_tokudb_ext) == 0)
|
||||
{
|
||||
//
|
||||
// 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
|
||||
//
|
||||
DB* db = NULL;
|
||||
error = db_create(&db, db_env, 0);
|
||||
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;
|
||||
DB* db = NULL;
|
||||
error = db_create(&db, db_env, 0);
|
||||
if (error) { goto cleanup; }
|
||||
|
||||
//
|
||||
// it is ok to do db->remove on any .tokudb file, because any such
|
||||
// file was created with db->open
|
||||
//
|
||||
error = db->remove(db, fname, NULL, 0);
|
||||
if (error) { goto cleanup; }
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue