Beispiel #1
0
def _archive_copy(src_st, src_path, dest_path):
    """
    Copy file from src_path to dest_path. Regular files and symlinks
    are supported. If an EnvironmentError occurs, then it is logged
    to stderr.

    @param src_st: source file lstat result
    @type src_st: posix.stat_result
    @param src_path: source file path
    @type src_path: str
    @param dest_path: destination file path
    @type dest_path: str
    """
    # Remove destination file in order to ensure that the following
    # symlink or copy2 call won't fail (see bug #535850).
    try:
        os.unlink(dest_path)
    except OSError:
        pass
    try:
        if stat.S_ISLNK(src_st.st_mode):
            os.symlink(os.readlink(src_path), dest_path)
        else:
            shutil.copy2(src_path, dest_path)
    except EnvironmentError as e:
        portage.util.writemsg(
            _("dispatch-conf: Error copying %(src_path)s to "
              "%(dest_path)s: %(reason)s\n") % {
                  "src_path": src_path,
                  "dest_path": dest_path,
                  "reason": e
              },
            noiselevel=-1,
        )
Beispiel #2
0
def _archive_copy(src_st, src_path, dest_path):
	"""
	Copy file from src_path to dest_path. Regular files and symlinks
	are supported. If an EnvironmentError occurs, then it is logged
	to stderr.

	@param src_st: source file lstat result
	@type src_st: posix.stat_result
	@param src_path: source file path
	@type src_path: str
	@param dest_path: destination file path
	@type dest_path: str
	"""
	# Remove destination file in order to ensure that the following
	# symlink or copy2 call won't fail (see bug #535850).
	try:
		os.unlink(dest_path)
	except OSError:
		pass
	try:
		if stat.S_ISLNK(src_st.st_mode):
			os.symlink(os.readlink(src_path), dest_path)
		else:
			shutil.copy2(src_path, dest_path)
	except EnvironmentError as e:
		portage.util.writemsg(
			_('dispatch-conf: Error copying %(src_path)s to '
			'%(dest_path)s: %(reason)s\n') % {
				"src_path": src_path,
				"dest_path": dest_path,
				"reason": e
			}, noiselevel=-1)