# Buggy code
def export_conanfile(output, paths, conanfile, origin_folder, conan_ref, keep_source):
    destination_folder = paths.export(conan_ref)
    previous_digest = _init_export_folder(destination_folder)
    execute_export(conanfile, origin_folder, destination_folder, output)

    digest = FileTreeManifest.create(destination_folder)
    save(os.path.join(destination_folder, CONAN_MANIFEST), str(digest))

    if previous_digest and previous_digest.file_sums == digest.file_sums:
        digest = previous_digest
        output.info("The stored package has not changed")
        modified_recipe = False
    else:
        output.success("A new %s version was exported" % CONANFILE)
        output.info("Folder: %s" % destination_folder)
        modified_recipe = True

    source = paths.source(conan_ref, conanfile.short_paths)
    dirty = os.path.join(source, DIRTY_FILE)
    remove = False
    if os.path.exists(dirty):
        output.info("Source folder is dirty, forcing removal")
        remove = True
    elif modified_recipe and not keep_source and os.path.exists(source):
        output.info("Package recipe modified in export, forcing source folder removal")
        output.info("Use the --keep-source, -k option to skip it")
        remove = True
    if remove:
        output.info("Removing 'source' folder, this can take a while for big packages")
        try:
            # remove only the internal
            rmdir(source)
        except BaseException as e:
            output.error(
                "Unable to delete source folder. Will be marked as dirty for deletion"
            )
            output.warn(str(e))
            save(os.path.join(source, DIRTY_FILE), "")


# 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 export_conanfile(output, paths, conanfile, origin_folder, conan_ref, keep_source):
    destination_folder = paths.export(conan_ref)
    previous_digest = _init_export_folder(destination_folder)
    execute_export(conanfile, origin_folder, destination_folder, output)

    digest = FileTreeManifest.create(destination_folder)
    save(os.path.join(destination_folder, CONAN_MANIFEST), str(digest))

    if previous_digest and previous_digest == digest:
        digest = previous_digest
        output.info("The stored package has not changed")
        modified_recipe = False
    else:
        output.success("A new %s version was exported" % CONANFILE)
        output.info("Folder: %s" % destination_folder)
        modified_recipe = True

    source = paths.source(conan_ref, conanfile.short_paths)
    dirty = os.path.join(source, DIRTY_FILE)
    remove = False
    if os.path.exists(dirty):
        output.info("Source folder is dirty, forcing removal")
        remove = True
    elif modified_recipe and not keep_source and os.path.exists(source):
        output.info("Package recipe modified in export, forcing source folder removal")
        output.info("Use the --keep-source, -k option to skip it")
        remove = True
    if remove:
        output.info("Removing 'source' folder, this can take a while for big packages")
        try:
            # remove only the internal
            rmdir(source)
        except BaseException as e:
            output.error(
                "Unable to delete source folder. Will be marked as dirty for deletion"
            )
            output.warn(str(e))
            save(os.path.join(source, DIRTY_FILE), "")