~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Brian Aker
  • Date: 2010-09-28 06:27:36 UTC
  • mto: (1800.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 1801.
  • Revision ID: brian@tangent.org-20100928062736-65a8ufnsji93fd99
Remove additional (maybe last of?) native_handle actual calls (safe_mutex is
historical and unused, so it does not count).

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/* Copy data from a textfile to table */
124
124
                List<Item> &set_values,
125
125
                enum enum_duplicates handle_duplicates, bool ignore)
126
126
{
 
127
  char name[FN_REFLEN];
127
128
  int file;
128
129
  Table *table= NULL;
129
130
  int error;
253
254
    return(true);
254
255
  }
255
256
 
256
 
  fs::path to_file(ex->file_name);
257
 
  fs::path target_path(fs::system_complete(getDataHomeCatalog()));
258
 
  if (not to_file.has_root_directory())
259
 
  {
260
 
    int count_elements= 0;
261
 
    for (fs::path::iterator iter= to_file.begin();
262
 
         iter != to_file.end();
263
 
         ++iter, ++count_elements)
264
 
    { }
265
 
 
266
 
    if (count_elements == 1)
267
 
    {
268
 
      target_path /= tdb;
269
 
    }
270
 
    target_path /= to_file;
271
 
  }
272
 
  else
273
 
  {
274
 
    target_path= to_file;
275
 
  }
276
 
 
277
 
  if (not secure_file_priv.string().empty())
278
 
  {
279
 
    if (target_path.file_string().substr(0, secure_file_priv.file_string().size()) != secure_file_priv.file_string())
280
 
    {
281
 
      /* Read only allowed from within dir specified by secure_file_priv */
282
 
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
257
  {
 
258
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
 
259
    ex->file_name+=dirname_length(ex->file_name);
 
260
#endif
 
261
    if (!internal::dirname_length(ex->file_name))
 
262
    {
 
263
      strcpy(name, getDataHomeCatalog().c_str());
 
264
      strncat(name, "/", 1);
 
265
      strncat(name, tdb, FN_REFLEN-getDataHomeCatalog().size());
 
266
      (void) internal::fn_format(name, ex->file_name, name, "",
 
267
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
 
268
    }
 
269
    else
 
270
    {
 
271
      (void) internal::fn_format(name, ex->file_name, getDataHomeCatalog().c_str(), "",
 
272
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
 
273
 
 
274
      if (opt_secure_file_priv)
 
275
      {
 
276
        fs::path secure_file_path(fs::system_complete(fs::path(opt_secure_file_priv)));
 
277
        fs::path target_path(fs::system_complete(fs::path(name)));
 
278
        if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
 
279
        {
 
280
          /* Read only allowed from within dir specified by secure_file_priv */
 
281
          my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
282
          return(true);
 
283
        }
 
284
      }
 
285
 
 
286
      struct stat stat_info;
 
287
      if (stat(name,&stat_info))
 
288
      {
 
289
        my_error(ER_FILE_NOT_FOUND, MYF(0), name, errno);
 
290
        return(true);
 
291
      }
 
292
 
 
293
      // if we are not in slave thread, the cursor must be:
 
294
      if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
 
295
            (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
 
296
            ((stat_info.st_mode & S_IFREG) == S_IFREG ||
 
297
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
 
298
      {
 
299
        my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
 
300
        return(true);
 
301
      }
 
302
      if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
 
303
        is_fifo = 1;
 
304
    }
 
305
    if ((file=internal::my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
 
306
    {
 
307
      my_error(ER_CANT_OPEN_FILE, MYF(0), name, errno);
283
308
      return(true);
284
309
    }
285
310
  }
286
311
 
287
 
  struct stat stat_info;
288
 
  if (stat(target_path.file_string().c_str(), &stat_info))
289
 
  {
290
 
    my_error(ER_FILE_NOT_FOUND, MYF(0), target_path.file_string().c_str(), errno);
291
 
    return(true);
292
 
  }
293
 
 
294
 
  // if we are not in slave thread, the cursor must be:
295
 
  if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
296
 
        (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
297
 
        ((stat_info.st_mode & S_IFREG) == S_IFREG ||
298
 
         (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
299
 
  {
300
 
    my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), target_path.file_string().c_str());
301
 
    return(true);
302
 
  }
303
 
  if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
304
 
    is_fifo = 1;
305
 
 
306
 
 
307
 
  if ((file=internal::my_open(target_path.file_string().c_str(), O_RDONLY,MYF(MY_WME))) < 0)
308
 
  {
309
 
    my_error(ER_CANT_OPEN_FILE, MYF(0), target_path.file_string().c_str(), errno);
310
 
    return(true);
311
 
  }
312
312
  CopyInfo info;
313
313
  memset(&info, 0, sizeof(info));
314
314
  info.ignore= ignore;
395
395
    error= -1;                          // Error on read
396
396
    goto err;
397
397
  }
398
 
 
399
 
  char msg[FN_REFLEN];
400
 
  snprintf(msg, sizeof(msg), ER(ER_LOAD_INFO), info.records, info.deleted,
 
398
  snprintf(name, sizeof(name), ER(ER_LOAD_INFO), info.records, info.deleted,
401
399
           (info.records - info.copied), session->cuted_fields);
402
400
 
403
401
  if (session->transaction.stmt.hasModifiedNonTransData())
404
402
    session->transaction.all.markModifiedNonTransData();
405
403
 
406
404
  /* ok to client sent only after binlog write and engine commit */
407
 
  session->my_ok(info.copied + info.deleted, 0, 0L, msg);
 
405
  session->my_ok(info.copied + info.deleted, 0, 0L, name);
408
406
err:
409
407
  assert(transactional_table || !(info.copied || info.deleted) ||
410
408
              session->transaction.stmt.hasModifiedNonTransData());
785
783
 
786
784
 
787
785
  /* Set of a stack for unget if long terminators */
788
 
  size_t length= max(field_term_length,line_term_length)+1;
789
 
  set_if_bigger(length, line_start.length());
 
786
  uint32_t length= max(field_term_length,line_term_length)+1;
 
787
  set_if_bigger(length,line_start.length());
790
788
  stack= stack_pos= (int*) memory::sql_alloc(sizeof(int)*length);
791
789
 
792
790
  if (!(buffer=(unsigned char*) calloc(1, buff_length+1)))