17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
22
#include <drizzled/function/str/strfunc.h>
22
23
#include <drizzled/function/str/load_file.h>
23
24
#include <drizzled/error.h>
24
25
#include <drizzled/data_home.h>
25
26
#include <drizzled/session.h>
26
#include "drizzled/internal/my_sys.h"
28
#include <boost/filesystem.hpp>
34
namespace fs=boost::filesystem;
40
28
String *Item_load_file::val_str(String *str)
42
30
assert(fixed == 1);
45
33
struct stat stat_info;
47
36
if (!(file_name= args[0]->val_str(str)))
53
fs::path target_path(fs::system_complete(getDataHomeCatalog()));
54
fs::path to_file(file_name->c_ptr());
55
if (not to_file.has_root_directory())
57
target_path /= to_file;
39
(void) fn_format(path, file_name->c_ptr(), drizzle_real_data_home, "",
40
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
64
42
/* Read only allowed from within dir specified by secure_file_priv */
65
if (not secure_file_priv.string().empty())
67
fs::path secure_file_path(fs::system_complete(secure_file_priv));
68
if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
70
/* Read only allowed from within dir specified by secure_file_priv */
71
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
43
if (opt_secure_file_priv &&
44
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
77
if (stat(target_path.file_string().c_str(), &stat_info))
79
my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr());
47
if (stat(path, &stat_info))
83
50
if (!(stat_info.st_mode & S_IROTH))
85
my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr());
52
/* my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr()); */
89
if (stat_info.st_size > (long) session.variables.max_allowed_packet)
55
if (stat_info.st_size > (long) current_session->variables.max_allowed_packet)
91
push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
57
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
92
58
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
93
59
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
94
func_name(), session.variables.max_allowed_packet);
98
if (stat_info.st_size == 0)
60
func_name(), current_session->variables.max_allowed_packet);
103
63
if (tmp_value.alloc((size_t)stat_info.st_size))
105
if ((file = internal::my_open(target_path.file_string().c_str(), O_RDONLY, MYF(0))) < 0)
107
if (internal::my_read(file, (unsigned char*) tmp_value.ptr(), (size_t)stat_info.st_size, MYF(MY_NABP)))
109
internal::my_close(file, MYF(0));
112
if (strlen(tmp_value.ptr()) == 0)
65
if ((file = my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0)
67
if (my_read(file, (unsigned char*) tmp_value.ptr(), (size_t)stat_info.st_size, MYF(MY_NABP)))
69
my_close(file, MYF(0));
116
72
tmp_value.length((size_t)stat_info.st_size);
117
internal::my_close(file, MYF(0));
73
my_close(file, MYF(0));
119
75
return(&tmp_value);