def _CopyFileLocal(source_filename, target_filename, copy_symlink=True):
import shutil<EOL>try:<EOL><INDENT>dir_name = os.path.dirname(target_filename)<EOL>if dir_name and not os.path.isdir(dir_name):<EOL><INDENT>os.makedirs(dir_name)<EOL><DEDENT>if copy_symlink and IsLink(source_filename):<EOL><INDENT>if os.path.isfile(target_filename) or IsLink(target_filename):<EOL><INDENT>DeleteFile(target_filename)<EOL><DEDENT>source_filename = ReadLink(source_filename)<EOL>CreateLink(source_filename, target_filename)<EOL><DEDENT>else:<EOL><INDENT>if sys.platform == '<STR_LIT:win32>':<EOL><INDENT>while IsLink(source_filename):<EOL><INDENT>link = ReadLink(source_filename)<EOL>if os.path.isabs(link):<EOL><INDENT>source_filename = link<EOL><DEDENT>else:<EOL><INDENT>source_filename = os.path.join(os.path.dirname(source_filename), link)<EOL><DEDENT><DEDENT><DEDENT>shutil.copyfile(source_filename, target_filename)<EOL>shutil.copymode(source_filename, target_filename)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>reraise(e, '<STR_LIT>' % (source_filename, target_filename))<EOL><DEDENT>
Copy a file locally to a directory.

:param unicode source_filename:
    The filename to copy from.

:param unicode target_filename:
    The filename to copy to.

:param bool copy_symlink:
    If True and source_filename is a symlink, target_filename will also be created as
    a symlink.

    If False, the file being linked will be copied instead.