equal
deleted
inserted
replaced
230 elif os.path.isfile(srcname): |
230 elif os.path.isfile(srcname): |
231 copyfile(srcname, dstname) |
231 copyfile(srcname, dstname) |
232 else: |
232 else: |
233 pass |
233 pass |
234 |
234 |
|
235 def opener(base): |
|
236 """ |
|
237 return a function that opens files relative to base |
|
238 |
|
239 this function is used to hide the details of COW semantics and |
|
240 remote file access from higher level code. |
|
241 |
|
242 todo: separate remote file access into a separate function |
|
243 """ |
|
244 p = base |
|
245 def o(path, mode="r"): |
|
246 if p.startswith("http://"): |
|
247 f = os.path.join(p, urllib.quote(path)) |
|
248 return httprangereader.httprangereader(f) |
|
249 |
|
250 f = os.path.join(p, path) |
|
251 |
|
252 mode += "b" # for that other OS |
|
253 |
|
254 if mode[0] != "r": |
|
255 try: |
|
256 s = os.stat(f) |
|
257 except OSError: |
|
258 d = os.path.dirname(f) |
|
259 if not os.path.isdir(d): |
|
260 os.makedirs(d) |
|
261 else: |
|
262 if s.st_nlink > 1: |
|
263 file(f + ".tmp", "wb").write(file(f, "rb").read()) |
|
264 rename(f+".tmp", f) |
|
265 |
|
266 return file(f, mode) |
|
267 |
|
268 return o |
|
269 |
235 def _makelock_file(info, pathname): |
270 def _makelock_file(info, pathname): |
236 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) |
271 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) |
237 os.write(ld, info) |
272 os.write(ld, info) |
238 os.close(ld) |
273 os.close(ld) |
239 |
274 |