Skip to content

Commit 056e85f

Browse files
committed
fixup! MDEV-36269: improve error handling for source command
1 parent 82ed328 commit 056e85f

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

client/my_readline.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct st_line_buffer
3737
extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, char * str);
3838
extern char *batch_readline(LINE_BUFFER *buffer, bool binary_mode);
3939
extern void batch_readline_end(LINE_BUFFER *buffer);
40-
extern bool init_line_buffer(LINE_BUFFER *buffer, File file, ulong size, ulong max_size);
40+
extern bool init_line_buffer(LINE_BUFFER *buffer, File file, ulong size,
41+
ulong max_size);
4142

4243
#endif /* CLIENT_MY_READLINE_INCLUDED */

client/mysql.cc

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,12 +1218,14 @@ static LINE_BUFFER *batch_readline_init(ulong max_size, const char *path)
12181218
{
12191219
if ((file= my_open(path, O_RDONLY | O_BINARY, MYF(0))) < 0)
12201220
{
1221-
#ifdef _WIN32
1222-
if (my_errno == EACCES && my_stat(path, &input_file_stat, MYF(0)) &&
1223-
MY_S_ISDIR(input_file_stat.st_mode))
1224-
goto errdir;
1225-
#endif
1226-
my_snprintf(buff, sizeof(buff), "Failed to open file '%.*s', error: %d",
1221+
#ifdef _WIN32
1222+
if (my_errno == EACCES)
1223+
goto errdir;
1224+
if (my_errno == EACCES && my_stat(path, &input_file_stat, MYF(0)) &&
1225+
MY_S_ISDIR(input_file_stat.st_mode))
1226+
goto errdir;
1227+
#endif
1228+
my_snprintf(buff, sizeof(buff), "Failed to open file '%.*s', error: %d",
12271229
FN_REFLEN, path, my_errno);
12281230
put_info(buff, INFO_ERROR, 0);
12291231
return 0;
@@ -1236,31 +1238,31 @@ static LINE_BUFFER *batch_readline_init(ulong max_size, const char *path)
12361238

12371239
if (my_fstat(file, &input_file_stat, MYF(0)))
12381240
{
1239-
my_snprintf(buff, sizeof(buff), "Failed to stat file '%.*s', error: %d",
1241+
my_snprintf(buff, sizeof(buff), "Failed to stat file '%.*s', error: %d",
12401242
FN_REFLEN, path ? path : "stdin", my_errno);
12411243
goto err1;
12421244
}
12431245

12441246
if (MY_S_ISDIR(input_file_stat.st_mode))
12451247
{
1246-
#ifdef _WIN32
1247-
errdir:
1248-
#endif
1249-
my_snprintf(buff, sizeof(buff), "Can't read from a directory '%.*s'",
1250-
FN_REFLEN, path ? path : "stdin");
1248+
#ifdef _WIN32
1249+
errdir:
1250+
#endif
1251+
my_snprintf(buff, sizeof(buff), "Can't read from a directory '%.*s'",
1252+
FN_REFLEN, path ? path : "stdin");
12511253
goto err1;
12521254
}
1253-
1255+
12541256
#ifndef _WIN32
12551257
if (MY_S_ISBLK(input_file_stat.st_mode))
12561258
{
1257-
my_snprintf(buff, sizeof(buff), "Can't read from a block device '%.*s'",
1259+
my_snprintf(buff, sizeof(buff), "Can't read from a block device '%.*s'",
12581260
FN_REFLEN, path ? path : "stdin");
12591261
goto err1;
12601262
}
12611263
#endif
12621264

1263-
if (!(line_buff= (LINE_BUFFER*) my_malloc(PSI_NOT_INSTRUMENTED,
1265+
if (!(line_buff= (LINE_BUFFER*) my_malloc(PSI_NOT_INSTRUMENTED,
12641266
sizeof(*line_buff),
12651267
MYF(MY_WME | MY_ZEROFILL))))
12661268
{
@@ -1275,12 +1277,12 @@ static LINE_BUFFER *batch_readline_init(ulong max_size, const char *path)
12751277

12761278
return line_buff;
12771279

1278-
err1:
1279-
put_info(buff, INFO_ERROR, 0);
1280-
err:
1281-
if (path)
1282-
my_close(file, MYF(0));
1283-
return 0;
1280+
err1:
1281+
put_info(buff, INFO_ERROR, 0);
1282+
err:
1283+
if (path)
1284+
my_close(file, MYF(0));
1285+
return 0;
12841286
}
12851287

12861288
static int delimiter_index= -1;

0 commit comments

Comments
 (0)