~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2009-07-11 08:51:36 UTC
  • mfrom: (1089.3.11 merge)
  • Revision ID: brian@gaz-20090711085136-qj01nwm3qynghwtc
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <mysys/my_pthread.h>
36
36
 
37
37
#include <drizzled/sql_select.h>
38
 
#include <mysys/my_dir.h>
39
38
#include <drizzled/error.h>
40
39
#include <drizzled/gettext.h>
41
40
#include <drizzled/nested_join.h>
46
45
#include <drizzled/check_stack_overrun.h>
47
46
#include <drizzled/lock.h>
48
47
#include <drizzled/listen.h>
 
48
#include <mysys/cached_directory.h>
 
49
 
 
50
using namespace std;
49
51
 
50
52
extern drizzled::TransactionServices transaction_services;
51
53
 
4998
5000
 
4999
5001
bool drizzle_rm_tmp_tables(ListenHandler &listen_handler)
5000
5002
{
5001
 
  uint32_t  idx;
5002
5003
  char  filePath[FN_REFLEN], filePathCopy[FN_REFLEN];
5003
 
  MY_DIR *dirp;
5004
 
  FILEINFO *file;
5005
5004
  Session *session;
5006
5005
 
5007
5006
  assert(drizzle_tmpdir);
5011
5010
  session->thread_stack= (char*) &session;
5012
5011
  session->store_globals();
5013
5012
 
 
5013
  CachedDirectory dir(drizzle_tmpdir);
 
5014
 
 
5015
  if (dir.fail())
 
5016
  {
 
5017
    my_errno= dir.getError();
 
5018
    my_error(ER_CANT_READ_DIR, MYF(0), drizzle_tmpdir, my_errno);
 
5019
    return true;
 
5020
  }
 
5021
 
 
5022
  CachedDirectory::Entries files= dir.getEntries();
 
5023
  CachedDirectory::Entries::iterator fileIter= files.begin();
 
5024
 
5014
5025
  /* Remove all temp tables in the tmpdir */
5015
 
  /* See if the directory exists */
5016
 
  if ((dirp = my_dir(drizzle_tmpdir ,MYF(MY_WME | MY_DONT_SORT))))
 
5026
  while (fileIter != files.end())
5017
5027
  {
5018
 
    /* Remove all SQLxxx tables from directory */
5019
 
    for (idx=0 ; idx < (uint32_t) dirp->number_off_files ; idx++)
 
5028
    CachedDirectory::Entry *entry= *fileIter;
 
5029
    string prefix= entry->filename.substr(0, TMP_FILE_PREFIX_LENGTH);
 
5030
 
 
5031
    if (prefix == TMP_FILE_PREFIX)
5020
5032
    {
5021
 
      file=dirp->dir_entry+idx;
5022
 
 
5023
 
      /* skiping . and .. */
5024
 
      if (file->name[0] == '.' && (!file->name[1] ||
5025
 
                                   (file->name[1] == '.' &&  !file->name[2])))
5026
 
        continue;
5027
 
 
5028
 
      if (!memcmp(file->name, TMP_FILE_PREFIX, TMP_FILE_PREFIX_LENGTH))
 
5033
      char *ext= fn_ext(entry->filename.c_str());
 
5034
      uint32_t ext_len= strlen(ext);
 
5035
      uint32_t filePath_len= snprintf(filePath, sizeof(filePath),
 
5036
                                      "%s%c%s", drizzle_tmpdir, FN_LIBCHAR,
 
5037
                                      entry->filename.c_str());
 
5038
 
 
5039
      if (ext_len && !memcmp(".dfe", ext, ext_len))
5029
5040
      {
5030
 
        char *ext= fn_ext(file->name);
5031
 
        uint32_t ext_len= strlen(ext);
5032
 
        uint32_t filePath_len= snprintf(filePath, sizeof(filePath),
5033
 
                                        "%s%c%s", drizzle_tmpdir, FN_LIBCHAR,
5034
 
                                        file->name);
5035
 
        if (!memcmp(".dfe", ext, ext_len))
 
5041
        TableShare share;
 
5042
        /* We should cut file extention before deleting of table */
 
5043
        memcpy(filePathCopy, filePath, filePath_len - ext_len);
 
5044
        filePathCopy[filePath_len - ext_len]= 0;
 
5045
        share.init(NULL, filePathCopy);
 
5046
        if (!open_table_def(session, &share))
5036
5047
        {
5037
 
          TableShare share;
5038
 
          /* We should cut file extention before deleting of table */
5039
 
          memcpy(filePathCopy, filePath, filePath_len - ext_len);
5040
 
          filePathCopy[filePath_len - ext_len]= 0;
5041
 
          share.init(NULL, filePathCopy);
5042
 
          if (!open_table_def(session, &share))
5043
 
          {
5044
 
            share.db_type()->deleteTable(session, filePathCopy);
5045
 
          }
5046
 
          share.free_table_share();
 
5048
          share.db_type()->deleteTable(session, filePathCopy);
5047
5049
        }
5048
 
        /*
5049
 
          File can be already deleted by tmp_table.file->delete_table().
5050
 
          So we hide error messages which happnes during deleting of these
5051
 
          files(MYF(0)).
5052
 
        */
5053
 
        my_delete(filePath, MYF(0));
 
5050
        share.free_table_share();
5054
5051
      }
 
5052
      /*
 
5053
        File can be already deleted by tmp_table.file->delete_table().
 
5054
        So we hide error messages which happnes during deleting of these
 
5055
        files(MYF(0)).
 
5056
      */
 
5057
      my_delete(filePath, MYF(0));
5055
5058
    }
5056
 
    my_dirend(dirp);
 
5059
 
 
5060
    ++fileIter;
5057
5061
  }
5058
5062
 
5059
5063
  delete session;