~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/catalog/engine.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <sys/stat.h>
25
25
#include <sys/types.h>
26
26
 
 
27
#include <boost/foreach.hpp>
27
28
#include <drizzled/display.h>
28
29
#include <google/protobuf/io/zero_copy_stream.h>
29
30
#include <google/protobuf/io/zero_copy_stream_impl.h>
44
45
 
45
46
bool Engine::create(const drizzled::identifier::Catalog &identifier, drizzled::message::catalog::shared_ptr &message)
46
47
{
47
 
  if (mkdir(identifier.getPath().c_str(), 0777) == -1)
 
48
  if (::mkdir(identifier.getPath().c_str(), 0777) == -1)
 
49
  {
48
50
    return false;
 
51
  }
49
52
 
50
53
  if (not writeFile(identifier, message))
51
54
  {
52
 
    rmdir(identifier.getPath().c_str());
 
55
    ::rmdir(identifier.getPath().c_str());
53
56
 
54
57
    return false;
55
58
  }
64
67
  file.append(CATALOG_OPT_EXT);
65
68
 
66
69
  // No catalog file, no love from us.
67
 
  if (access(file.c_str(), F_OK))
68
 
  {
69
 
    perror(file.c_str());
70
 
    return false;
71
 
  }
72
 
 
73
 
  if (unlink(file.c_str()))
74
 
  {
75
 
    perror(file.c_str());
76
 
    return false;
77
 
  }
78
 
 
79
 
  if (rmdir(identifier.getPath().c_str()))
80
 
  {
81
 
    perror(identifier.getPath().c_str());
82
 
    //@todo If this happens, we want a report of it. For the moment I dump
83
 
    //to stderr so I can catch it in Hudson.
 
70
  if (::access(file.c_str(), F_OK))
 
71
  {
 
72
    drizzled::sql_perror("access()", file);
 
73
    return false;
 
74
  }
 
75
 
 
76
  if (::unlink(file.c_str()))
 
77
  {
 
78
    drizzled::sql_perror("unlink()", file);
 
79
    return false;
 
80
  }
 
81
 
 
82
  if (::rmdir(identifier.getPath().c_str()))
 
83
  {
 
84
    drizzled::sql_perror("rmdir()", identifier.getPath());
 
85
    //@todo If this happens, we want a report of it. For the moment I dump to
 
86
    //stderr so I can catch it in Hudson.
84
87
    drizzled::CachedDirectory dir(identifier.getPath());
85
88
  }
86
89
 
92
95
  prime(messages);
93
96
}
94
97
 
95
 
drizzled::message::catalog::shared_ptr Engine::getMessage(drizzled::identifier::Catalog::const_reference identifier)
 
98
drizzled::message::catalog::shared_ptr Engine::getMessage(const drizzled::identifier::Catalog& identifier)
96
99
{
97
100
  if (drizzled::catalog::local_identifier() == identifier)
98
101
  {
116
119
  drizzled::CachedDirectory::Entries files= directory.getEntries();
117
120
 
118
121
 
119
 
  for (drizzled::CachedDirectory::Entries::iterator fileIter= files.begin();
120
 
       fileIter != files.end(); fileIter++)
 
122
  BOOST_FOREACH(drizzled::CachedDirectory::Entries::reference entry, files)
121
123
  {
122
 
    drizzled::CachedDirectory::Entry *entry= *fileIter;
123
124
    drizzled::message::catalog::shared_ptr message;
124
125
 
125
126
    if (not entry->filename.compare(GLOBAL_TEMPORARY_EXT))
 
127
    {
126
128
      continue;
 
129
    }
127
130
 
128
131
    drizzled::identifier::Catalog identifier(entry->filename);
129
132
 
132
135
      messages.push_back(message);
133
136
 
134
137
      if (drizzled::catalog::local_identifier() == identifier)
 
138
      {
135
139
        found_local= true;
 
140
      }
136
141
    }
137
142
  }
138
143
 
139
 
  if (not found_local)
 
144
  if (found_local == false)
140
145
  {
141
146
    messages.push_back(drizzled::catalog::local()->message());
142
147
  }
147
152
  char file_tmp[FN_REFLEN];
148
153
  std::string file(identifier.getPath());
149
154
 
150
 
 
151
155
  file.append(1, FN_LIBCHAR);
152
156
  file.append(CATALOG_OPT_EXT);
153
157
 
157
161
 
158
162
  if (fd == -1)
159
163
  {
160
 
    perror(file_tmp);
 
164
    drizzled::sql_perror("mkstemp()", file_tmp);
161
165
 
162
166
    return false;
163
167
  }
172
176
    success= false;
173
177
  }
174
178
 
175
 
  if (not success)
 
179
  if (success == false)
176
180
  {
177
181
    drizzled::my_error(drizzled::ER_CORRUPT_CATALOG_DEFINITION, MYF(0), file.c_str(),
178
182
                       message->InitializationErrorString().empty() ? "unknown" :  message->InitializationErrorString().c_str());
179
183
 
180
 
    if (close(fd) == -1)
181
 
      perror(file_tmp);
182
 
 
183
 
    if (unlink(file_tmp))
184
 
      perror(file_tmp);
185
 
 
186
 
    return false;
187
 
  }
188
 
 
189
 
  if (close(fd) == -1)
190
 
  {
191
 
    perror(file_tmp);
192
 
 
193
 
    if (unlink(file_tmp))
194
 
      perror(file_tmp);
195
 
 
196
 
    return false;
197
 
  }
198
 
 
199
 
  if (rename(file_tmp, file.c_str()) == -1)
200
 
  {
201
 
    if (unlink(file_tmp))
202
 
      perror(file_tmp);
 
184
    if (::close(fd) == -1)
 
185
    {
 
186
      drizzled::sql_perror("close()", file_tmp);
 
187
    }
 
188
 
 
189
    if (::unlink(file_tmp))
 
190
    {
 
191
      drizzled::sql_perror("unlink()", file_tmp);
 
192
    }
 
193
 
 
194
    return false;
 
195
  }
 
196
 
 
197
  if (::close(fd) == -1)
 
198
  {
 
199
    drizzled::sql_perror("close()", file_tmp);
 
200
 
 
201
    if (::unlink(file_tmp))
 
202
    {
 
203
      drizzled::sql_perror("unlink()", file_tmp);
 
204
    }
 
205
 
 
206
    return false;
 
207
  }
 
208
 
 
209
  if (::rename(file_tmp, file.c_str()) == -1)
 
210
  {
 
211
    drizzled::sql_perror("rename()", file_tmp);
 
212
    if (::unlink(file_tmp))
 
213
    {
 
214
      drizzled::sql_perror("unlink()", file_tmp);
 
215
    }
203
216
 
204
217
    return false;
205
218
  }
208
221
}
209
222
 
210
223
 
211
 
drizzled::message::catalog::shared_ptr Engine::readFile(drizzled::identifier::Catalog::const_reference identifier)
 
224
drizzled::message::catalog::shared_ptr Engine::readFile(const drizzled::identifier::Catalog& identifier)
212
225
{
213
226
  std::string path(identifier.getPath());
214
227
 
239
252
  }
240
253
  else
241
254
  {
242
 
    perror(path.c_str());
 
255
    drizzled::sql_perror("std::fstream::good()", path);
243
256
  }
244
257
 
245
258
  return drizzled::message::catalog::shared_ptr();