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
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)
999
fs::path to_file(exchange->file_name);
997
uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
999
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
1000
option|= MY_REPLACE_DIR; // Force use of db directory
1003
if (!internal::dirname_length(exchange->file_name))
1002
if (not to_file.has_root_directory())
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())
1007
int count_elements= 0;
1008
for (fs::path::iterator iter= to_file.begin();
1009
iter != to_file.end();
1010
++iter, ++count_elements)
1013
if (count_elements == 1)
1015
target_path /= session->db;
1018
target_path /= to_file;
1012
(void) internal::fn_format(path, exchange->file_name, getDataHomeCatalog().c_str(), "", option);
1022
target_path = exchange->file_name;
1014
if (opt_secure_file_priv)
1025
if (not secure_file_priv.string().empty())
1016
fs::path secure_file_path(fs::system_complete(fs::path(opt_secure_file_priv)));
1017
fs::path target_path(fs::system_complete(fs::path(path)));
1018
if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
1027
if (target_path.file_string().substr(0, secure_file_priv.file_string().size()) != secure_file_priv.file_string())
1020
1029
/* Write only allowed to dir or subdir specified by secure_file_priv */
1021
1030
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
1026
if (!access(path, F_OK))
1035
if (!access(target_path.file_string().c_str(), F_OK))
1028
1037
my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name);
1031
1040
/* Create the file world readable */
1032
if ((file= internal::my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1041
if ((file= internal::my_create(target_path.file_string().c_str(), 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1034
1043
(void) fchmod(file, 0666); // Because of umask()
1035
1044
if (init_io_cache(cache, file, 0L, internal::WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1037
1046
internal::my_close(file, MYF(0));
1038
internal::my_delete(path, MYF(0)); // Delete file on error, it was just created
1047
internal::my_delete(target_path.file_string().c_str(), MYF(0)); // Delete file on error, it was just created
1049
1058
bool string_results= false, non_string_results= false;
1051
1060
if ((uint32_t) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN)
1052
strncpy(path,exchange->file_name,FN_REFLEN-1);
1062
path= exchange->file_name;
1054
1065
/* Check if there is any blobs in data */
1326
1337
if (!res) // If NULL
1328
1339
if (my_b_write(cache,(unsigned char*) "",1))
1331
1342
else if (my_b_write(cache,(unsigned char*) res->ptr(),res->length()))
1333
my_error(ER_ERROR_ON_WRITE, MYF(0), path, errno);
1344
my_error(ER_ERROR_ON_WRITE, MYF(0), path.file_string().c_str(), errno);