~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2010-02-26 19:08:27 UTC
  • mto: (1309.2.7 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1313.
  • Revision ID: brian@gaz-20100226190827-ztb9qoxc9tt43jwc
Cleanup of rm schema;

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 
59
59
static long mysql_rm_known_files(Session *session,
60
60
                                 const string &db, const char *path,
61
 
                                 set<string> &dropped_tables);
 
61
                                 plugin::TableNameList &dropped_tables);
62
62
static void mysql_change_db_impl(Session *session, LEX_STRING *new_db_name);
63
63
 
64
64
/*
216
216
  int error= false;
217
217
  char  path[FN_REFLEN+16];
218
218
  uint32_t length;
219
 
  set<string> dropped_tables;
 
219
  plugin::TableNameList dropped_tables;
220
220
  message::Schema schema_proto;
221
221
 
222
222
  /*
298
298
    db_len= schema_name.length();
299
299
 
300
300
    ReplicationServices &replication_services= ReplicationServices::singleton();
301
 
    for (set<string>::iterator it= dropped_tables.begin();
 
301
    for (plugin::TableNameList::iterator it= dropped_tables.begin();
302
302
         it != dropped_tables.end();
303
303
         it++)
304
304
    {
490
490
static long mysql_rm_known_files(Session *session,
491
491
                                 const string &db,
492
492
                                 const char *org_path,
493
 
                                 set<string> &dropped_tables)
 
493
                                 plugin::TableNameList &dropped_tables)
494
494
{
495
495
  CachedDirectory dirp(org_path);
496
496
  if (dirp.fail())
497
497
    return 0;
498
498
 
499
499
  long deleted= 0;
500
 
  char filePath[FN_REFLEN];
501
500
  TableList *tot_list= NULL, **tot_list_next;
502
501
 
503
502
  tot_list_next= &tot_list;
504
503
 
505
504
  plugin::StorageEngine::getTableNames(db, dropped_tables);
506
505
 
507
 
  for (CachedDirectory::Entries::const_iterator iter= dirp.getEntries().begin();
508
 
       iter != dirp.getEntries().end() && !session->killed;
509
 
       ++iter)
 
506
  for (plugin::TableNameList::iterator it= dropped_tables.begin();
 
507
       it != dropped_tables.end();
 
508
       it++)
510
509
  {
511
 
    string filename((*iter)->filename);
512
 
 
513
 
    /* skiping . and .. */
514
 
    if (filename[0] == '.' && (!filename[1] ||
515
 
       (filename[1] == '.' &&  !filename[2])))
516
 
      continue;
517
 
 
518
 
    string extension("");
519
 
    size_t ext_pos= filename.rfind('.');
520
 
    if (ext_pos != string::npos)
521
 
    {
522
 
      extension= filename.substr(ext_pos);
523
 
    }
524
 
    if (deletable_extentions.find(extension) == deletable_extentions.end())
525
 
    {
526
 
      /*
527
 
        ass ass ass.
528
 
 
529
 
        strange checking for magic extensions that are then deleted if
530
 
        not reg_ext (i.e. .frm).
531
 
 
532
 
        and (previously) we'd err out on drop database if files not matching
533
 
        engine ha_known_exts() or deletable_extensions were present.
534
 
 
535
 
        presumably this was to avoid deleting other user data... except if that
536
 
        data happened to be in files ending in .BAK, .opt or .TMD. *fun*
537
 
       */
538
 
      continue;
539
 
    }
540
 
    /* just for safety we use files_charset_info */
541
 
    if (!my_strcasecmp(files_charset_info, extension.c_str(), ".dfe"))
542
 
    {
543
 
      size_t db_len= db.size();
544
 
 
545
 
      /* Drop the table nicely */
546
 
      filename.erase(ext_pos);
547
 
      TableList *table_list=(TableList*)
548
 
                             session->calloc(sizeof(*table_list) +
549
 
                                             db_len + 1 +
550
 
                                             filename.size() + 1);
551
 
 
552
 
      if (!table_list)
553
 
        return -1;
554
 
      table_list->db= (char*) (table_list+1);
555
 
      table_list->table_name= strcpy(table_list->db, db.c_str()) + db_len + 1;
556
 
      filename_to_tablename(filename.c_str(), table_list->table_name,
557
 
                            filename.size() + 1);
558
 
      table_list->alias= table_list->table_name;  // If lower_case_table_names=2
559
 
      table_list->internal_tmp_table= (strncmp(filename.c_str(),
560
 
                                               TMP_FILE_PREFIX,
561
 
                                               strlen(TMP_FILE_PREFIX)) == 0);
562
 
      /* Link into list */
563
 
      (*tot_list_next)= table_list;
564
 
      tot_list_next= &table_list->next_local;
565
 
      deleted++;
566
 
    }
567
 
    else
568
 
    {
569
 
      sprintf(filePath, "%s/%s", org_path, filename.c_str());
570
 
      if (internal::my_delete_with_symlink(filePath,MYF(MY_WME)))
571
 
      {
572
 
        return -1;
573
 
      }
574
 
    }
 
510
    size_t db_len= db.size();
 
511
 
 
512
    /* Drop the table nicely */
 
513
    TableList *table_list=(TableList*)
 
514
      session->calloc(sizeof(*table_list) +
 
515
                      db_len + 1 +
 
516
                      (*it).length() + 1);
 
517
 
 
518
    if (not table_list)
 
519
      return -1;
 
520
 
 
521
    table_list->db= (char*) (table_list+1);
 
522
    table_list->table_name= strcpy(table_list->db, db.c_str()) + db_len + 1;
 
523
    filename_to_tablename((*it).c_str(), table_list->table_name,
 
524
                          (*it).size() + 1);
 
525
    table_list->alias= table_list->table_name;  // If lower_case_table_names=2
 
526
    table_list->internal_tmp_table= (strncmp((*it).c_str(),
 
527
                                             TMP_FILE_PREFIX,
 
528
                                             strlen(TMP_FILE_PREFIX)) == 0);
 
529
    /* Link into list */
 
530
    (*tot_list_next)= table_list;
 
531
    tot_list_next= &table_list->next_local;
 
532
    deleted++;
575
533
  }
576
534
  if (session->killed)
577
535
    return -1;