Dulwich.io dulwich / f9030f0
Avoid double call to os.lstat. Jelmer Vernooń≥ 3 years ago
1 changed file(s) with 7 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
420420 :param target_path: Path to write to
421421 :param honor_filemode: An optional flag to honor core.filemode setting in
422422 config file, default is core.filemode=True, change executable bit
423 :return: stat object for the file
423424 """
424425 try:
425 oldstat = os.stat(target_path)
426 oldstat = os.lstat(target_path)
426427 except OSError as e:
427428 if e.errno == errno.ENOENT:
428429 oldstat = None
438439 if oldstat is not None and oldstat.st_size == len(contents):
439440 with open(target_path, 'rb') as f:
440441 if f.read() == contents:
441 return
442 return oldstat
442443
443444 with open(target_path, 'wb') as f:
444445 # Write out file
446447
447448 if honor_filemode:
448449 os.chmod(target_path, mode)
450
451 return os.lstat(target_path)
449452
450453
451454 INVALID_DOTNAMES = (b".git", b".", b"..", b"")
507510 # FIXME: Merge new index into working tree
508511 if S_ISGITLINK(entry.mode):
509512 os.mkdir(full_path)
513 st = os.lstat(full_path)
510514 else:
511515 obj = object_store[entry.sha]
512 build_file_from_blob(obj, entry.mode, full_path,
516 st = build_file_from_blob(obj, entry.mode, full_path,
513517 honor_filemode=honor_filemode)
514518 # Add file to index
515 st = os.lstat(full_path)
516519 if not honor_filemode or S_ISGITLINK(entry.mode):
517520 # we can not use tuple slicing to build a new tuple,
518521 # because on windows that will convert the times to