1 | /* Copyright (C) 2006-2008 MySQL AB |
2 | |
3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ |
15 | |
16 | #include "../maria_def.h" |
17 | #ifdef _WIN32 |
18 | #include <direct.h> /* rmdir */ |
19 | #endif |
20 | |
21 | my_bool maria_log_remove(const char *testdir) |
22 | { |
23 | MY_DIR *dirp; |
24 | uint i; |
25 | MY_STAT stat_buff; |
26 | char file_name[FN_REFLEN]; |
27 | |
28 | /* Removes control file */ |
29 | if (fn_format(file_name, CONTROL_FILE_BASE_NAME, |
30 | maria_data_root, "" , MYF(MY_WME)) == NullS) |
31 | return 1; |
32 | if (my_stat(file_name, &stat_buff, MYF(0)) && |
33 | my_delete(file_name, MYF(MY_WME)) != 0) |
34 | return 1; |
35 | |
36 | /* Finds and removes transaction log files */ |
37 | if (!(dirp = my_dir(maria_data_root, MYF(MY_DONT_SORT)))) |
38 | return 1; |
39 | |
40 | for (i= 0; i < dirp->number_of_files; i++) |
41 | { |
42 | char *file= dirp->dir_entry[i].name; |
43 | if (strncmp(file, "aria_log." , 9) == 0 && |
44 | file[9] >= '0' && file[9] <= '9' && |
45 | file[10] >= '0' && file[10] <= '9' && |
46 | file[11] >= '0' && file[11] <= '9' && |
47 | file[12] >= '0' && file[12] <= '9' && |
48 | file[13] >= '0' && file[13] <= '9' && |
49 | file[14] >= '0' && file[14] <= '9' && |
50 | file[15] >= '0' && file[15] <= '9' && |
51 | file[16] >= '0' && file[16] <= '9' && |
52 | file[17] == '\0') |
53 | { |
54 | if (fn_format(file_name, file, |
55 | maria_data_root, "" , MYF(MY_WME)) == NullS || |
56 | my_delete(file_name, MYF(MY_WME)) != 0) |
57 | { |
58 | my_dirend(dirp); |
59 | return 1; |
60 | } |
61 | } |
62 | } |
63 | my_dirend(dirp); |
64 | if (testdir) |
65 | rmdir(testdir); |
66 | return 0; |
67 | } |
68 | |
69 | char *create_tmpdir(const char *progname) |
70 | { |
71 | static char test_dirname[FN_REFLEN]; |
72 | char tmp_name[FN_REFLEN]; |
73 | size_t length; |
74 | |
75 | /* Create a temporary directory of name TMP-'executable', but without the -t extension */ |
76 | fn_format(tmp_name, progname, "" , "" , MY_REPLACE_DIR | MY_REPLACE_EXT); |
77 | length= strlen(tmp_name); |
78 | if (length > 2 && tmp_name[length-2] == '-' && tmp_name[length-1] == 't') |
79 | tmp_name[length-2]= 0; |
80 | strxmov(test_dirname, "TMP-" , tmp_name, NullS); |
81 | |
82 | /* |
83 | Don't give an error if we can't create dir, as it may already exist from a previously aborted |
84 | run |
85 | */ |
86 | (void) my_mkdir(test_dirname, 0777, MYF(0)); |
87 | return test_dirname; |
88 | } |
89 | |