def build_file_from_blob(blob, mode, target_path, honor_filemode=True):
 try:
  oldstat = os.lstat(target_path)
 except OSError as e:
  if (e.errno == errno.ENOENT):
   oldstat = None
  else:
   raise
 contents = blob.as_raw_string()
 if stat.S_ISLNK(mode):
  if oldstat:
   os.unlink(target_path)
  os.symlink(contents, target_path)
 else:
  if ((oldstat is not None) and (oldstat.st_size == len(contents))):
   with open(target_path, 'rb') as f:
    if (f.read() == contents):
     return oldstat
  with open(target_path, 'wb') as f:
   f.write(contents)
  if honor_filemode:
   os.chmod(target_path, mode)
 return os.lstat(target_path)

def build_file_from_blob ( blob , mode , target_path , honor_filemode = True ) : try : oldstat = os . lstat ( target_path ) except OSError as e : if ( e . errno == errno . ENOENT ) : oldstat = None else : raise contents = blob . as_raw_string ( ) if stat . S_ISLNK ( mode ) : if oldstat : os . unlink ( target_path ) os . symlink ( contents , target_path ) else : if ( ( oldstat is not None ) and ( oldstat . st_size == len ( contents ) ) ) : with open ( target_path , 'rb' ) as f : if ( f . read ( ) == contents ) : return oldstat with open ( target_path , 'wb' ) as f : f . write ( contents ) if honor_filemode : os . chmod ( target_path , mode ) return os . lstat ( target_path )
build a file or symlink on disk based on a git object .