~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Monty Taylor
  • Date: 2010-10-05 18:58:54 UTC
  • mto: (1819.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1820.
  • Revision ID: mordred@inaugust.com-20101005185854-5aj3ui8csyp50hlx
Made data_home be fs::path natively.

Show diffs side-by-side

added added

removed removed

Lines of Context:
913
913
  {
914
914
    (void) end_io_cache(cache);
915
915
    (void) internal::my_close(file, MYF(0));
916
 
    (void) internal::my_delete(path, MYF(0));           // Delete file on error
 
916
    (void) internal::my_delete(path.file_string().c_str(), MYF(0));             // Delete file on error
917
917
    file= -1;
918
918
  }
919
919
}
947
947
    (void) internal::my_close(file, MYF(0));
948
948
    file= -1;
949
949
  }
950
 
  path[0]= '\0';
 
950
  path.clear();
951
951
  row_count= 0;
952
952
}
953
953
 
957
957
    cache(static_cast<internal::IO_CACHE *>(memory::sql_calloc(sizeof(internal::IO_CACHE)))),
958
958
    row_count(0L)
959
959
{
960
 
  path[0]=0;
 
960
  path.clear();
961
961
}
962
962
 
963
963
select_to_file::~select_to_file()
991
991
*/
992
992
 
993
993
 
994
 
static int create_file(Session *session, char *path, file_exchange *exchange, internal::IO_CACHE *cache)
 
994
static int create_file(Session *session,
 
995
                       fs::path &target_path,
 
996
                       file_exchange *exchange,
 
997
                       internal::IO_CACHE *cache)
995
998
{
 
999
  fs::path to_file(exchange->file_name);
996
1000
  int file;
997
 
  uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
998
 
 
999
 
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
1000
 
  option|= MY_REPLACE_DIR;                      // Force use of db directory
1001
 
#endif
1002
 
 
1003
 
  if (!internal::dirname_length(exchange->file_name))
 
1001
 
 
1002
  if (not to_file.has_root_directory())
1004
1003
  {
1005
 
    strcpy(path, getDataHomeCatalog().c_str());
1006
 
    strncat(path, "/", 1);
1007
 
    if (! session->db.empty())
1008
 
      strncat(path, session->db.c_str(), FN_REFLEN-getDataHomeCatalog().size());
1009
 
    (void) internal::fn_format(path, exchange->file_name, path, "", option);
 
1004
    target_path= fs::system_complete(getDataHomeCatalog());
 
1005
    if (not session->db.empty())
 
1006
    {
 
1007
      int count_elements= 0;
 
1008
      for (fs::path::iterator iter= to_file.begin();
 
1009
           iter != to_file.end();
 
1010
           ++iter, ++count_elements)
 
1011
      { }
 
1012
 
 
1013
      if (count_elements == 1)
 
1014
      {
 
1015
        target_path /= session->db;
 
1016
      }
 
1017
    }
 
1018
    target_path /= to_file;
1010
1019
  }
1011
1020
  else
1012
 
    (void) internal::fn_format(path, exchange->file_name, getDataHomeCatalog().c_str(), "", option);
 
1021
  {
 
1022
    target_path = exchange->file_name;
 
1023
  }
1013
1024
 
1014
1025
  if (not secure_file_priv.string().empty())
1015
1026
  {
1016
1027
    fs::path secure_file_path(fs::system_complete(secure_file_priv));
1017
 
    fs::path target_path(fs::system_complete(fs::path(path)));
1018
1028
    if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
1019
1029
    {
1020
1030
      /* Write only allowed to dir or subdir specified by secure_file_priv */
1023
1033
    }
1024
1034
  }
1025
1035
 
1026
 
  if (!access(path, F_OK))
 
1036
  if (!access(target_path.file_string().c_str(), F_OK))
1027
1037
  {
1028
1038
    my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name);
1029
1039
    return -1;
1030
1040
  }
1031
1041
  /* Create the file world readable */
1032
 
  if ((file= internal::my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
 
1042
  if ((file= internal::my_create(target_path.file_string().c_str(), 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1033
1043
    return file;
1034
1044
  (void) fchmod(file, 0666);                    // Because of umask()
1035
1045
  if (init_io_cache(cache, file, 0L, internal::WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1036
1046
  {
1037
1047
    internal::my_close(file, MYF(0));
1038
 
    internal::my_delete(path, MYF(0));  // Delete file on error, it was just created
 
1048
    internal::my_delete(target_path.file_string().c_str(), MYF(0));  // Delete file on error, it was just created
1039
1049
    return -1;
1040
1050
  }
1041
1051
  return file;
1049
1059
  bool string_results= false, non_string_results= false;
1050
1060
  unit= u;
1051
1061
  if ((uint32_t) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN)
1052
 
    strncpy(path,exchange->file_name,FN_REFLEN-1);
 
1062
  {
 
1063
    path= exchange->file_name;
 
1064
  }
1053
1065
 
1054
1066
  /* Check if there is any blobs in data */
1055
1067
  {
1330
1342
    }
1331
1343
    else if (my_b_write(cache,(unsigned char*) res->ptr(),res->length()))
1332
1344
    {
1333
 
      my_error(ER_ERROR_ON_WRITE, MYF(0), path, errno);
 
1345
      my_error(ER_ERROR_ON_WRITE, MYF(0), path.file_string().c_str(), errno);
1334
1346
      goto err;
1335
1347
    }
1336
1348
  }