~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_engine/schema.cc

  • Committer: Brian Aker
  • Date: 2010-03-27 04:01:18 UTC
  • mto: This revision was merged to the branch mainline in revision 1411.
  • Revision ID: brian@gaz-20100327040118-0xkvwy01vc43xwgp
Small update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
  table_definition_ext= DEFAULT_FILE_EXTENSION;
60
60
  pthread_rwlock_init(&schema_lock, NULL);
61
61
  prime();
62
 
#if 0
63
 
  message::Schema schema_message;
64
 
 
65
 
  schema_message.set_name("temporary_tables");
66
 
 
67
 
  doCreateSchema(schema_message);
68
 
#endif
69
62
}
70
63
 
71
64
Schema::~Schema()
327
320
  char schema_file_tmp[FN_REFLEN];
328
321
  string schema_file(path);
329
322
 
330
 
  snprintf(schema_file_tmp, FN_REFLEN, "%s%c%s.tmpXXXXXX", path, FN_LIBCHAR, MY_DB_OPT_FILE);
331
323
 
332
324
  schema_file.append(1, FN_LIBCHAR);
333
325
  schema_file.append(MY_DB_OPT_FILE);
334
326
 
 
327
  snprintf(schema_file_tmp, FN_REFLEN, "%sXXXXXX", schema_file.c_str());
 
328
 
335
329
  int fd= mkstemp(schema_file_tmp);
336
330
 
337
331
  if (fd == -1)
338
332
  {
339
333
    perror(schema_file_tmp);
 
334
 
340
335
    return false;
341
336
  }
342
337
 
343
338
  if (not db.SerializeToFileDescriptor(fd))
344
339
  {
345
340
    cerr << "Couldn't write " << path << "\n";
346
 
    close(fd);
 
341
 
 
342
    if (close(fd) == -1)
 
343
      perror(schema_file_tmp);
 
344
 
 
345
    if (unlink(schema_file_tmp))
 
346
      perror(schema_file_tmp);
 
347
 
 
348
    return false;
 
349
  }
 
350
 
 
351
  if (close(fd) == -1)
 
352
  {
 
353
    perror(schema_file_tmp);
 
354
 
 
355
    if (unlink(schema_file_tmp))
 
356
      perror(schema_file_tmp);
347
357
 
348
358
    return false;
349
359
  }
350
360
 
351
361
  if (rename(schema_file_tmp, schema_file.c_str()) == -1)
352
362
  {
353
 
    close(fd);
 
363
    if (unlink(schema_file_tmp))
 
364
      perror(schema_file_tmp);
354
365
 
355
366
    return false;
356
367
  }
357
 
  close(fd);
358
368
 
359
369
  return true;
360
370
}