177 f.write('b') |
177 f.write('b') |
178 f.close() |
178 f.close() |
179 print("* file y created") |
179 print("* file y created") |
180 print(repo.cached) |
180 print(repo.cached) |
181 |
181 |
|
182 def antiambiguity(): |
|
183 filename = 'ambigcheck' |
|
184 |
|
185 # try some times, because reproduction of ambiguity depends on |
|
186 # "filesystem time" |
|
187 for i in xrange(5): |
|
188 fp = open(filename, 'w') |
|
189 fp.write('FOO') |
|
190 fp.close() |
|
191 |
|
192 oldstat = os.stat(filename) |
|
193 if oldstat.st_ctime != oldstat.st_mtime: |
|
194 # subsequent changing never causes ambiguity |
|
195 continue |
|
196 |
|
197 repetition = 3 |
|
198 |
|
199 # repeat changing via checkambigatclosing, to examine whether |
|
200 # st_mtime is advanced multiple times as expecetd |
|
201 for i in xrange(repetition): |
|
202 # explicit closing |
|
203 fp = scmutil.checkambigatclosing(open(filename, 'a')) |
|
204 fp.write('FOO') |
|
205 fp.close() |
|
206 |
|
207 # implicit closing by "with" statement |
|
208 with scmutil.checkambigatclosing(open(filename, 'a')) as fp: |
|
209 fp.write('BAR') |
|
210 |
|
211 newstat = os.stat(filename) |
|
212 if oldstat.st_ctime != newstat.st_ctime: |
|
213 # timestamp ambiguity was naturally avoided while repetition |
|
214 continue |
|
215 |
|
216 # st_mtime should be advanced "repetition * 2" times, because |
|
217 # all changes occured at same time (in sec) |
|
218 expected = (oldstat.st_mtime + repetition * 2) & 0x7fffffff |
|
219 if newstat.st_mtime != expected: |
|
220 print("'newstat.st_mtime %s is not %s (as %s + %s * 2)" % |
|
221 (newstat.st_mtime, expected, oldstat.st_mtime, repetition)) |
|
222 |
|
223 # no more examination is needed regardless of result |
|
224 break |
|
225 else: |
|
226 # This platform seems too slow to examine anti-ambiguity |
|
227 # of file timestamp (or test happened to be executed at |
|
228 # bad timing). Exit silently in this case, because running |
|
229 # on other faster platforms can detect problems |
|
230 pass |
|
231 |
182 print('basic:') |
232 print('basic:') |
183 print() |
233 print() |
184 basic(fakerepo()) |
234 basic(fakerepo()) |
185 print() |
235 print() |
186 print('fakeuncacheable:') |
236 print('fakeuncacheable:') |