| 5004 | static int check_temp_dir_result= 0; |
| 5005 | |
| 5006 | static |
| 5007 | int check_temp_dir(char* tmp_file) |
| 5008 | { |
| 5009 | File fd; |
| 5010 | int result= 1; // Assume failure |
| 5011 | MY_DIR *dirp; |
| 5012 | char tmp_dir[FN_REFLEN]; |
| 5013 | size_t tmp_dir_size; |
| 5014 | DBUG_ENTER("check_temp_dir"); |
| 5015 | |
| 5016 | /* This look is safe to use as this function is only called once */ |
| 5017 | mysql_mutex_lock(&LOCK_start_thread); |
| 5018 | if (check_temp_dir_run) |
| 5019 | { |
| 5020 | if ((result= check_temp_dir_result)) |
| 5021 | my_message(result, tmp_file, MYF(0)); |
| 5022 | goto end; |
| 5023 | } |
| 5024 | check_temp_dir_run= 1; |
| 5025 | |
| 5026 | /* |
| 5027 | Get the directory from the temporary file. |
| 5028 | */ |
| 5029 | dirname_part(tmp_dir, tmp_file, &tmp_dir_size); |
| 5030 | |
| 5031 | /* |
| 5032 | Check if the directory exists. |
| 5033 | */ |
| 5034 | if (!(dirp=my_dir(tmp_dir,MYF(MY_WME)))) |
| 5035 | goto end; |
| 5036 | my_dirend(dirp); |
| 5037 | |
| 5038 | /* |
| 5039 | Check permissions to create a file. We use O_TRUNC to ensure that |
| 5040 | things works even if we happen to have and old file laying around. |
| 5041 | */ |
| 5042 | if ((fd= mysql_file_create(key_file_misc, |
| 5043 | tmp_file, CREATE_MODE, |
| 5044 | O_WRONLY | O_BINARY | O_TRUNC | O_NOFOLLOW, |
| 5045 | MYF(MY_WME))) < 0) |
| 5046 | goto end; |
| 5047 | |
| 5048 | result= 0; // Directory name ok |
| 5049 | /* |
| 5050 | Clean up. |
| 5051 | */ |
| 5052 | mysql_file_close(fd, MYF(0)); |
| 5053 | mysql_file_delete(key_file_misc, tmp_file, MYF(0)); |
| 5054 | |
| 5055 | end: |
| 5056 | mysql_mutex_unlock(&LOCK_start_thread); |
| 5057 | DBUG_RETURN(result); |
| 5058 | } |
| 5059 | |
| 5060 | |
| 5061 | void |
no test coverage detected