# Buggy code
def run_deploy(conanfile, install_folder, output):
    deploy_output = ScopedOutput("%s deploy()" % output.scope, output)
    file_importer = _FileImporter(conanfile, install_folder)
    package_copied = set()

    # This is necessary to capture FileCopier full destination paths
    # Maybe could be improved in FileCopier
    def file_copier(*args, **kwargs):
        file_copy = FileCopier(conanfile.package_folder, install_folder)
        copied = file_copy(*args, **kwargs)
        package_copied.update(copied)

    conanfile.copy_deps = file_importer
    conanfile.copy = file_copier
    conanfile.install_folder = install_folder
    with get_env_context_manager(conanfile):
        with tools.chdir(install_folder):
            conanfile.deploy()

    copied_files = file_importer.copied_files
    copied_files.update(package_copied)
    _report_save_manifest(
        copied_files, deploy_output, install_folder, "deploy_manifest.txt"
    )


# Traceback (ValueError)
conan install -u --build=outdated --set build_type=Release --set compiler=Visual Studio --set compiler.runtime=MT D:\dev\ruggedsw\base\dds\test


PROJECT: Installing D:\dev\ruggedsw\base\dds\test\conanfile.txt
Requirements
Boost/1.66.0-0@rugged/stable from shuttle
google.test/1.8.0-0@rugged/stable from shuttle
rugged.base/develop@demo/testing from local
rugged.cmake/0.2.0@rugged/stable from shuttle
rugged.dds/develop@demo/testing from local
rugged.idl.coredx.cpp/develop@demo/testing from local
twinoaks.coredx/4.0.16-0@rugged/stable from shuttle
twinoaks.coredx.license/latest@rugged/stable from shuttle
Packages
Boost/1.66.0-0@rugged/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9
google.test/1.8.0-0@rugged/stable:7ce94352b9d6c95dd4f54be06f40814de83033cc
rugged.base/develop@demo/testing:0360a5f1de3610acad6fc54319fae7f93d69080f
rugged.cmake/0.2.0@rugged/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9
rugged.dds/develop@demo/testing:be478f16b38bce7c5b9b377d28de2be18dd0f742
rugged.idl.coredx.cpp/develop@demo/testing:cf3c4eea01e24ccdb48737197cec263338b785dc
twinoaks.coredx/4.0.16-0@rugged/stable:7bd6f2c3d5c4e48a75805376b58cde753392f711
twinoaks.coredx.license/latest@rugged/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9

Boost/1.66.0-0@rugged/stable: Package is up to date
google.test/1.8.0-0@rugged/stable: Package is up to date
rugged.cmake/0.2.0@rugged/stable: Package is up to date
twinoaks.coredx/4.0.16-0@rugged/stable: Package is up to date
twinoaks.coredx.license/latest@rugged/stable: Package is up to date
rugged.base/develop@demo/testing: Package is up to date
rugged.idl.coredx.cpp/develop@demo/testing: Package is up to date
rugged.dds/develop@demo/testing: Package is up to date
Boost/1.66.0-0@rugged/stable: Already installed!
google.test/1.8.0-0@rugged/stable: Already installed!
rugged.cmake/0.2.0@rugged/stable: Already installed!
twinoaks.coredx/4.0.16-0@rugged/stable: Already installed!
twinoaks.coredx.license/latest@rugged/stable: Already installed!
rugged.base/develop@demo/testing: Already installed!
rugged.idl.coredx.cpp/develop@demo/testing: Already installed!
rugged.dds/develop@demo/testing: Already installed!
PROJECT: Generator cmake created conanbuildinfo.cmake
PROJECT: Generator txt created conanbuildinfo.txt
PROJECT: Generated conaninfo.txt
Traceback (most recent call last):
File "c:\program files\python35\lib\site-packages\conans\model\ref.py", line 70, in loads
name, version, user, channel = tokens
ValueError: not enough values to unpack (expected 4, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\program files\python35\lib\site-packages\conans\client\command.py", line 243, in install
reference = ConanFileReference.loads(args.path)
File "c:\program files\python35\lib\site-packages\conans\model\ref.py", line 73, in loads
"OpenCV/1.0.6@user/stable" % text)
conans.errors.ConanException: Wrong package recipe reference D:\dev\ruggedsw\base\dds\test
Write something like OpenCV/1.0.6@user/stable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\program files\python35\lib\site-packages\conans\client\command.py", line 1099, in run
method(args[0][1:])
File "c:\program files\python35\lib\site-packages\conans\client\command.py", line 254, in install
install_folder=args.install_folder)
File "c:\program files\python35\lib\site-packages\conans\client\conan_api.py", line 63, in wrapper
return f(*args, **kwargs)
File "c:\program files\python35\lib\site-packages\conans\client\conan_api.py", line 402, in install
no_imports=no_imports)
File "c:\program files\python35\lib\site-packages\conans\client\manager.py", line 385, in install
run_imports(conanfile, install_folder, output)
File "c:\program files\python35\lib\site-packages\conans\client\importer.py", line 72, in run_imports
conanfile.imports()
File "c:\program files\python35\lib\site-packages\conans\client\loader_parse.py", line 175, in imports
conan_file.copy(*import_params)
File "c:\program files\python35\lib\site-packages\conans\client\importer.py", line 139, in __call__
excludes=excludes)
File "c:\program files\python35\lib\site-packages\conans\client\file_copier.py", line 77, in __call__
copied_files = self._copy_files(files_to_copy, src, dst, keep_path, links)
File "c:\program files\python35\lib\site-packages\conans\client\file_copier.py", line 171, in _copy_files
shutil.copy2(abs_src_name, abs_dst_name)
File "c:\program files\python35\lib\shutil.py", line 251, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "c:\program files\python35\lib\shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'D:\\dev\\ruggedsw\\base\\dds\\test\\build.vs.Release.Static\\CoreDXeval.lic'

ERROR: [Errno 13] Permission denied: 'D:\\dev\\ruggedsw\\base\\dds\\test\\build.vs.Release.Static\\CoreDXeval.lic'

# Fixed code
def run_deploy(conanfile, install_folder, output):
    deploy_output = ScopedOutput("%s deploy()" % output.scope, output)
    file_importer = _FileImporter(conanfile, install_folder)
    package_copied = set()

    # This is necessary to capture FileCopier full destination paths
    # Maybe could be improved in FileCopier
    def file_copier(*args, **kwargs):
        file_copy = FileCopier(conanfile.package_folder, install_folder)
        copied = file_copy(*args, **kwargs)
        _make_files_writable(copied)
        package_copied.update(copied)

    conanfile.copy_deps = file_importer
    conanfile.copy = file_copier
    conanfile.install_folder = install_folder
    with get_env_context_manager(conanfile):
        with tools.chdir(install_folder):
            conanfile.deploy()

    copied_files = file_importer.copied_files
    copied_files.update(package_copied)
    _report_save_manifest(
        copied_files, deploy_output, install_folder, "deploy_manifest.txt"
    )