]>
Commit | Line | Data |
---|---|---|
16604d53 ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.2.077 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.2.077 (after 7.2.076) | |
11 | Problem: rename(from, to) doesn't work if "from" and "to" differ only in | |
12 | case on a system that ignores case in file names. | |
13 | Solution: Go through another file name. | |
14 | Files: src/fileio.c | |
15 | ||
16 | ||
17 | *** ../vim-7.2.076/src/fileio.c Tue Dec 30 16:15:16 2008 | |
18 | --- src/fileio.c Wed Dec 31 14:59:59 2008 | |
19 | *************** | |
20 | *** 6106,6117 **** | |
21 | #ifdef HAVE_ACL | |
22 | vim_acl_T acl; /* ACL from original file */ | |
23 | #endif | |
24 | ||
25 | /* | |
26 | ! * When the names are identical, there is nothing to do. | |
27 | */ | |
28 | if (fnamecmp(from, to) == 0) | |
29 | ! return 0; | |
30 | ||
31 | /* | |
32 | * Fail if the "from" file doesn't exist. Avoids that "to" is deleted. | |
33 | --- 6106,6129 ---- | |
34 | #ifdef HAVE_ACL | |
35 | vim_acl_T acl; /* ACL from original file */ | |
36 | #endif | |
37 | + #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME) | |
38 | + int use_tmp_file = FALSE; | |
39 | + #endif | |
40 | ||
41 | /* | |
42 | ! * When the names are identical, there is nothing to do. When they refer | |
43 | ! * to the same file (ignoring case and slash/backslash differences) but | |
44 | ! * the file name differs we need to go through a temp file. | |
45 | */ | |
46 | if (fnamecmp(from, to) == 0) | |
47 | ! { | |
48 | ! #ifdef CASE_INSENSITIVE_FILENAME | |
49 | ! if (STRCMP(gettail(from), gettail(to)) != 0) | |
50 | ! use_tmp_file = TRUE; | |
51 | ! else | |
52 | ! #endif | |
53 | ! return 0; | |
54 | ! } | |
55 | ||
56 | /* | |
57 | * Fail if the "from" file doesn't exist. Avoids that "to" is deleted. | |
58 | *************** | |
59 | *** 6122,6128 **** | |
60 | #ifdef UNIX | |
61 | { | |
62 | struct stat st_to; | |
63 | - char tempname[MAXPATHL + 1]; | |
64 | ||
65 | /* It's possible for the source and destination to be the same file. | |
66 | * This happens when "from" and "to" differ in case and are on a FAT32 | |
67 | --- 6134,6139 ---- | |
68 | *************** | |
69 | *** 6130,6162 **** | |
70 | if (mch_stat((char *)to, &st_to) >= 0 | |
71 | && st.st_dev == st_to.st_dev | |
72 | && st.st_ino == st_to.st_ino) | |
73 | { | |
74 | ! /* Find a name that doesn't exist and is in the same directory. | |
75 | ! * Move "from" to "tempname" and then to "to". */ | |
76 | ! if (STRLEN(from) >= MAXPATHL - 5) | |
77 | ! return -1; | |
78 | ! STRCPY(tempname, from); | |
79 | ! for (n = 123; n < 99999; ++n) | |
80 | { | |
81 | ! sprintf(gettail(tempname), "%d", n); | |
82 | ! if (mch_stat(tempname, &st_to) < 0) | |
83 | { | |
84 | ! if (mch_rename((char *)from, tempname) == 0) | |
85 | ! { | |
86 | ! if (mch_rename(tempname, (char *)to) == 0) | |
87 | ! return 0; | |
88 | ! /* Strange, the second step failed. Try moving the | |
89 | ! * file back and return failure. */ | |
90 | ! mch_rename(tempname, (char *)from); | |
91 | ! return -1; | |
92 | ! } | |
93 | ! /* If it fails for one temp name it will most likely fail | |
94 | ! * for any temp name, give up. */ | |
95 | return -1; | |
96 | } | |
97 | } | |
98 | - return -1; | |
99 | } | |
100 | } | |
101 | #endif | |
102 | ||
103 | --- 6141,6182 ---- | |
104 | if (mch_stat((char *)to, &st_to) >= 0 | |
105 | && st.st_dev == st_to.st_dev | |
106 | && st.st_ino == st_to.st_ino) | |
107 | + use_tmp_file = TRUE; | |
108 | + } | |
109 | + #endif | |
110 | + | |
111 | + #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME) | |
112 | + if (use_tmp_file) | |
113 | + { | |
114 | + char tempname[MAXPATHL + 1]; | |
115 | + | |
116 | + /* | |
117 | + * Find a name that doesn't exist and is in the same directory. | |
118 | + * Rename "from" to "tempname" and then rename "tempname" to "to". | |
119 | + */ | |
120 | + if (STRLEN(from) >= MAXPATHL - 5) | |
121 | + return -1; | |
122 | + STRCPY(tempname, from); | |
123 | + for (n = 123; n < 99999; ++n) | |
124 | { | |
125 | ! sprintf((char *)gettail((char_u *)tempname), "%d", n); | |
126 | ! if (mch_stat(tempname, &st) < 0) | |
127 | { | |
128 | ! if (mch_rename((char *)from, tempname) == 0) | |
129 | { | |
130 | ! if (mch_rename(tempname, (char *)to) == 0) | |
131 | ! return 0; | |
132 | ! /* Strange, the second step failed. Try moving the | |
133 | ! * file back and return failure. */ | |
134 | ! mch_rename(tempname, (char *)from); | |
135 | return -1; | |
136 | } | |
137 | + /* If it fails for one temp name it will most likely fail | |
138 | + * for any temp name, give up. */ | |
139 | + return -1; | |
140 | } | |
141 | } | |
142 | + return -1; | |
143 | } | |
144 | #endif | |
145 | ||
146 | *** ../vim-7.2.076/src/version.c Tue Dec 30 16:15:16 2008 | |
147 | --- src/version.c Wed Dec 31 16:19:29 2008 | |
148 | *************** | |
149 | *** 678,679 **** | |
150 | --- 678,681 ---- | |
151 | { /* Add new patch number below this line */ | |
152 | + /**/ | |
153 | + 77, | |
154 | /**/ | |
155 | ||
156 | -- | |
157 | We apologise again for the fault in the subtitles. Those responsible for | |
158 | sacking the people who have just been sacked have been sacked. | |
159 | "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD | |
160 | ||
161 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
162 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
163 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
164 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |