# Buggy code
def upload_package(
    self, package_reference, remote, retry, retry_wait, skip_upload=False
):
    """Will upload the package to the first remote"""
    t1 = time.time()
    # existing package, will use short paths if defined
    package_folder = self._client_cache.package(package_reference, short_paths=None)
    # Get all the files in that directory
    files = gather_files(package_folder)

    self._output.rewrite_line("Checking package integrity...")
    if CONANINFO not in files or CONAN_MANIFEST not in files:
        logger.error("Missing info or manifest in uploading files: %s" % (str(files)))
        raise ConanException(
            "Cannot upload corrupted package '%s'" % str(package_reference)
        )

    logger.debug("====> Time remote_manager build_files_set : %f" % (time.time() - t1))

    # If package has been modified remove tgz to regenerate it
    read_manifest, expected_manifest = self._client_cache.package_manifests(
        package_reference
    )

    if read_manifest is None or read_manifest.file_sums != expected_manifest.file_sums:
        self._output.writeln("")
        for fname in read_manifest.file_sums.keys():
            if read_manifest.file_sums[fname] != expected_manifest.file_sums[fname]:
                self._output.warn(
                    "Mismatched checksum for file %s (checksum: %s, expected: %s)"
                    % (
                        fname,
                        read_manifest.file_sums[fname],
                        expected_manifest.file_sums[fname],
                    )
                )

        if PACKAGE_TGZ_NAME in files:
            try:
                tgz_path = os.path.join(package_folder, PACKAGE_TGZ_NAME)
                os.unlink(tgz_path)
            except Exception:
                pass
        logger.error(
            "Manifests doesn't match!: %s != %s"
            % (str(read_manifest.file_sums), str(expected_manifest.file_sums))
        )
        raise ConanException(
            "Cannot upload corrupted package '%s'" % str(package_reference)
        )
    else:
        self._output.rewrite_line("Package integrity OK!")
    self._output.writeln("")
    logger.debug(
        "====> Time remote_manager check package integrity : %f" % (time.time() - t1)
    )
    the_files = compress_package_files(files, package_folder, self._output)
    if not skip_upload:
        tmp = self._call_remote(
            remote, "upload_package", package_reference, the_files, retry, retry_wait
        )

        duration = time.time() - t1
        log_package_upload(package_reference, duration, the_files, remote)
        logger.debug("====> Time remote_manager upload_package: %f" % duration)
        return tmp
    else:
        return None


# Traceback (KeyError)
D:\slave\ws\cab\extern\boost\1.63.0@0\ws>conan.exe upload "Boost/1.63.0@cab/extern" --all --confirm -r bop --retry 3
Uploading Boost/1.63.0@cab/extern

Compressing recipe...
Uploading conanmanifest.txt


Uploading conan_export.tgz

Uploaded conan recipe 'Boost/1.63.0@cab/extern' to 'bop': http://conan.bop
Uploading package 1/5: 4f0fd3886115d238859ac2a3d41664e4236efc61

Checking package integrity...
Package integrity OK!

Compressing package...
Requesting upload permissions...
Requesting upload permissions...Done!

Uploading conan_package.tgz

Uploading package 2/5: 5d34366328ff5fe8b9f93b912e5855ffb5fda596

Checking package integrity...
Traceback (most recent call last):
File "C:\Python34\Scripts\conan-script.py", line 9, in <module>
load_entry_point('conan==0.19.2', 'console_scripts', 'conan')()
File "C:\Python34\lib\site-packages\conans\conan.py", line 6, in run
main(sys.argv[1:])
File "C:\Python34\lib\site-packages\conans\client\command.py", line 1065, in main
error = command.run(args)
File "C:\Python34\lib\site-packages\conans\client\command.py", line 979, in run
raise exc
File "C:\Python34\lib\site-packages\conans\client\command.py", line 959, in run
method(args[0][1:])
File "C:\Python34\lib\site-packages\conans\client\command.py", line 826, in upload
retry_wait=args.retry_wait)
File "C:\Python34\lib\site-packages\conans\client\manager.py", line 540, in upload
retry=retry, retry_wait=retry_wait)
File "C:\Python34\lib\site-packages\conans\client\uploader.py", line 41, in upload_conan
self._upload_conan(conan_ref, force, all_packages, retry, retry_wait)
File "C:\Python34\lib\site-packages\conans\client\uploader.py", line 56, in _upload_conan
retry, retry_wait)
File "C:\Python34\lib\site-packages\conans\client\uploader.py", line 76, in upload_package
self._remote_proxy.upload_package(package_ref, retry, retry_wait)
File "C:\Python34\lib\site-packages\conans\client\proxy.py", line 295, in upload_package
result = self._remote_manager.upload_package(package_ref, remote, retry, retry_wait)
File "C:\Python34\lib\site-packages\conans\client\remote_manager.py", line 77, in upload_package
if read_manifest.file_sums[fname] != expected_manifest.file_sums[fname]:
KeyError: 'include/boost/asio/ip/unicast.hpp'

# Fixed code
def upload_package(
    self, package_reference, remote, retry, retry_wait, skip_upload=False
):
    """Will upload the package to the first remote"""
    t1 = time.time()
    # existing package, will use short paths if defined
    package_folder = self._client_cache.package(package_reference, short_paths=None)
    # Get all the files in that directory
    files = gather_files(package_folder)

    self._output.rewrite_line("Checking package integrity...")
    if CONANINFO not in files or CONAN_MANIFEST not in files:
        logger.error("Missing info or manifest in uploading files: %s" % (str(files)))
        raise ConanException(
            "Cannot upload corrupted package '%s'" % str(package_reference)
        )

    logger.debug("====> Time remote_manager build_files_set : %f" % (time.time() - t1))

    # If package has been modified remove tgz to regenerate it
    read_manifest, expected_manifest = self._client_cache.package_manifests(
        package_reference
    )

    if read_manifest != expected_manifest:
        self._output.writeln("")
        diff = read_manifest.difference(expected_manifest)
        for fname, (h1, h2) in diff.items():
            self._output.warn(
                "Mismatched checksum '%s' (manifest: %s, file: %s)" % (fname, h1, h2)
            )

        if PACKAGE_TGZ_NAME in files:
            try:
                tgz_path = os.path.join(package_folder, PACKAGE_TGZ_NAME)
                os.unlink(tgz_path)
            except Exception:
                pass
        error_msg = os.linesep.join(
            "Mismatched checksum '%s' (manifest: %s, file: %s)" % (fname, h1, h2)
            for fname, (h1, h2) in diff.items()
        )
        logger.error("Manifests doesn't match!\n%s" % error_msg)
        raise ConanException(
            "Cannot upload corrupted package '%s'" % str(package_reference)
        )
    else:
        self._output.rewrite_line("Package integrity OK!")
    self._output.writeln("")
    logger.debug(
        "====> Time remote_manager check package integrity : %f" % (time.time() - t1)
    )
    the_files = compress_package_files(files, package_folder, self._output)
    if not skip_upload:
        tmp = self._call_remote(
            remote, "upload_package", package_reference, the_files, retry, retry_wait
        )

        duration = time.time() - t1
        log_package_upload(package_reference, duration, the_files, remote)
        logger.debug("====> Time remote_manager upload_package: %f" % duration)
        return tmp
    else:
        return None