mysql_config_edit_MySQL新特性之mysql_config_editor源码解析

static int set_command(void)

{

DBUG_ENTER("set_command");

DYNAMIC_STRING file_buf, path_buf;

init_dynamic_string(&path_buf, "", MY_LINE_MAX, MY_LINE_MAX);

init_dynamic_string(&file_buf, "", file_size, 3 * MY_LINE_MAX);

if (tty_password)

opt_password= get_tty_password(NullS);

if (file_size)

{

if (read_and_decrypt_file(&file_buf) == -1) //如果文件存在,就读取文件,并将文件的密文解密后存放到file_buf中.

goto error;

}

dynstr_append(&path_buf, "["); /* --login=path */

if (opt_login_path)

dynstr_append(&path_buf, opt_login_path);

else

dynstr_append(&path_buf, "client");

dynstr_append(&path_buf, "]");

if (opt_user) /* --user */

{

dynstr_append(&path_buf, "\nuser = ");

dynstr_append(&path_buf, opt_user);

}

if (opt_password) /* --password */

{

dynstr_append(&path_buf, "\npassword = ");

dynstr_append(&path_buf, opt_password);

}

if (opt_host) /* --host */

{

dynstr_append(&path_buf, "\nhost = ");

dynstr_append(&path_buf, opt_host);

}

if (opt_socket)

{

dynstr_append(&path_buf, "\nsocket = ");

dynstr_append(&path_buf, opt_socket);

}

if (opt_port)

{

dynstr_append(&path_buf, "\nport = ");

dynstr_append(&path_buf, opt_port);

}

dynstr_append(&path_buf, "\n");

/* Warn if login path already exists */

if (opt_warn && ((locate_login_path (&file_buf, opt_login_path)) //判断该login-path是否已经存在

!= NULL))

{

int choice;

printf ("WARNING : \'%s\' path already exists and will be "

"overwritten. \n Continue? (Press y|Y for Yes, any "

"other key for No) : ",

opt_login_path);

choice= getchar();

if (choice != (int) 'y' && choice != (int) 'Y’) //如果login-path存在是否选择覆盖

goto done; /* skip */

}

/* Remove the login path. */

remove_login_path(&file_buf, opt_login_path); //从原来文件中读取的内容中,删掉该login-path信息

/* Append the new login path to the file buffer. */

dynstr_append(&file_buf, path_buf.str); //将该login-path的信息加到file_buf的末尾

if (encrypt_and_write_file(&file_buf) == -1) //将包含新的log-path的所有信息和原来的信息加密写入文件

goto error;

done:

dynstr_free(&file_buf);

dynstr_free(&path_buf);

DBUG_RETURN(0);

error:

dynstr_free(&file_buf);

dynstr_free(&path_buf);

DBUG_RETURN(-1);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值