101
102
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length)
106
106
if (!memcmp(from, TMP_FILE_PREFIX, TMP_FILE_PREFIX_LENGTH))
108
108
/* Temporary table name. */
109
res= strlen(strncpy(to, from, to_length));
109
length= strlen(strncpy(to, from, to_length));
113
res= strconvert(&my_charset_filename, from,
114
system_charset_info, to, to_length, &errors);
115
if (errors) // Old 5.0 name
113
for (; *from && length < to_length; length++, from++)
118
strncat(to, from, to_length-1);
120
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid (old?) table or database name '%s'"), from);
120
/* We've found an escaped char - skip the @ */
122
/* There will be a three-position hex-char version of the char */
123
for (int x=2; x >= 0; x--)
125
if (*from >= '0' && *from <= '9')
126
to[length] += ((*from++ - '0') << (4 * x));
127
else if (*from >= 'a' && *from <= 'f')
128
to[length] += ((*from++ - 'a' + 10) << (4 * x));
130
/* Backup because we advanced extra in the inner loop */
132
143
tablename_to_filename()
133
from The table name in system_charset_info.
134
to OUT The file name in my_charset_filename.
135
146
to_length The size of the file name buffer.
149
true if errors happen. false on success.
140
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length)
152
bool tablename_to_filename(const char *from, char *to, size_t to_length)
142
uint32_t errors, length;
144
length= strconvert(system_charset_info, from,
145
&my_charset_filename, to, to_length, &errors);
156
for (; *from && length < to_length; length++, from++)
158
if ((*from >= '0' && *from <= '9') ||
159
(*from >= 'A' && *from <= 'Z') ||
160
(*from >= 'a' && *from <= 'z') ||
161
(*from == '_') || (*from == ' ') ||
162
((unsigned char)*from >= 128))
168
if (length + 4 >= to_length)
171
/* We need to escape this char in a way that can be reversed */
173
to[length++]= hexchars[(*from >> 8) & 15];
174
to[length++]= hexchars[(*from >> 4) & 15];
175
to[length]= hexchars[(*from) & 15];
146
178
if (check_if_legal_tablename(to) &&
147
179
length + 4 < to_length)
149
181
memcpy(to + length, "@@@", 4);
160
192
build_table_filename()
161
buff Where to write result in my_charset_filename.
193
buff Where to write result
162
194
This may be the same as table_name.
163
195
bufflen buff size
164
db Database name in system_charset_info.
165
table_name Table name in system_charset_info.
197
table_name Table name
166
198
ext File extension.
167
199
flags FN_FROM_IS_TMP or FN_TO_IS_TMP or FN_IS_TMP
168
200
table_name is temporary, do not change.
189
221
size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table_name, bool is_tmp)
192
223
char dbbuff[FN_REFLEN];
193
224
char tbbuff[FN_REFLEN];
194
int rootdir_len= strlen(FN_ROOTDIR);
225
bool conversion_error= false;
227
memset(tbbuff, 0, sizeof(tbbuff));
196
228
if (is_tmp) // FN_FROM_IS_TMP | FN_TO_IS_TMP
197
229
strncpy(tbbuff, table_name, sizeof(tbbuff));
199
tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
232
conversion_error= tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
233
if (conversion_error)
235
errmsg_printf(ERRMSG_LVL_ERROR,
236
_("Table name cannot be encoded and fit within filesystem "
237
"name length restrictions."));
241
memset(dbbuff, 0, sizeof(dbbuff));
242
conversion_error= tablename_to_filename(db, dbbuff, sizeof(dbbuff));
243
if (conversion_error)
245
errmsg_printf(ERRMSG_LVL_ERROR,
246
_("Schema name cannot be encoded and fit within filesystem "
247
"name length restrictions."));
201
tablename_to_filename(db, dbbuff, sizeof(dbbuff));
202
table_path= drizzle_data_home;
252
int rootdir_len= strlen(FN_ROOTDIR);
253
string table_path(drizzle_data_home);
203
254
int without_rootdir= table_path.length()-rootdir_len;
205
256
/* Don't add FN_ROOTDIR if dirzzle_data_home already includes it */
206
257
if (without_rootdir >= 0)
208
char *tmp= (char*)table_path.c_str()+without_rootdir;
259
const char *tmp= table_path.c_str()+without_rootdir;
209
260
if (memcmp(tmp, FN_ROOTDIR, rootdir_len) != 0)
210
261
table_path.append(FN_ROOTDIR);