@known_failure_githubci_win
@with_tree(tree=(('a.tar.gz', {'d': {fn_in_archive_obscure: '123'}}), ('simple.txt', '123'), (fn_archive_obscure_ext, (('d', ((fn_in_archive_obscure, '123'),)),)), (fn_archive_obscure, '123')))
@with_tempfile()
def test_basic_scenario(d=None, d2=None):
    (fn_archive, fn_extracted) = (fn_archive_obscure_ext, fn_archive_obscure)
    annex = AnnexRepo(d, backend='MD5E')
    annex.init_remote(ARCHIVES_SPECIAL_REMOTE, ['encryption=none', 'type=external', ('externaltype=%s' % ARCHIVES_SPECIAL_REMOTE), 'autoenable=true'])
    assert annex.is_special_annex_remote(ARCHIVES_SPECIAL_REMOTE)
    assert (fn_extracted != fn_in_archive_obscure)
    annex.add(fn_archive)
    annex.commit(msg='Added tarball')
    annex.add(fn_extracted)
    annex.commit(msg='Added the load file')
    annexcr = ArchiveAnnexCustomRemote(annex=None, path=d)
    eq_(annexcr.get_file_url(archive_key='xyz', file='a.dat'), 'dl+archive:xyz#path=a.dat')
    eq_(annexcr.get_file_url(archive_key='xyz', file='a.dat', size=999), 'dl+archive:xyz#path=a.dat&size=999')
    eq_(annexcr._parse_url('dl+archive:xyz/a.dat#size=999'), ('xyz', 'a.dat', {'size': 999}))
    eq_(annexcr._parse_url('dl+archive:xyz/a.dat'), ('xyz', 'a.dat', {}))
    eq_(annexcr._parse_url('dl+archive:xyz#path=a.dat&size=999'), ('xyz', 'a.dat', {'size': 999}))
    eq_(annexcr._parse_url('dl+archive:xyz#path=a.dat'), ('xyz', 'a.dat', {}))
    file_url = annexcr.get_file_url(archive_file=fn_archive, file=((fn_archive.replace('.tar.gz', '') + '/d/') + fn_in_archive_obscure))
    annex.add_url_to_file(fn_extracted, file_url, ['--relaxed'])
    annex.drop(fn_extracted)
    list_of_remotes = annex.whereis(fn_extracted, output='descriptions')
    in_(('[%s]' % ARCHIVES_SPECIAL_REMOTE), list_of_remotes)
    assert_false(annex.file_has_content(fn_extracted))
    with swallow_logs(new_level=logging.INFO) as cml:
        annex.get(fn_extracted)
        cml.assert_logged(msg='datalad-archives special remote is using an extraction', level='INFO', regex=False)
    assert_true(annex.file_has_content(fn_extracted))
    annex.rm_url(fn_extracted, file_url)
    assert_raises(CommandError, annex.drop, fn_extracted)
    annex.add_url_to_file(fn_extracted, file_url)
    annex.drop(fn_extracted)
    annex.get(fn_extracted)
    annex.drop(fn_extracted)
    cloned_annex = AnnexRepo.clone(d, d2)
    assert_false(cloned_annex.file_has_content(fn_archive))
    assert_false(cloned_annex.file_has_content(fn_extracted))
    cloned_annex.get(fn_extracted)
    assert_true(cloned_annex.file_has_content(fn_extracted))
    assert_true(cloned_annex.file_has_content(fn_archive))
@known_failure_githubci_win
@with_tree(tree=(('a.tar.gz', {'d': {fn_in_archive_obscure: '123'}}), ('simple.txt', '123'), (fn_archive_obscure_ext, (('d', ((fn_in_archive_obscure, '123'),)),)), (fn_archive_obscure, '123')))
@with_tempfile()
def test_basic_scenario(d=None, d2=None):
    (fn_archive, fn_extracted) = (fn_archive_obscure_ext, fn_archive_obscure)
    annex = AnnexRepo(d, backend='MD5E')
    annex.init_remote(ARCHIVES_SPECIAL_REMOTE, ['encryption=none', 'type=external', ('externaltype=%s' % ARCHIVES_SPECIAL_REMOTE), 'autoenable=true'])
    assert annex.is_special_annex_remote(ARCHIVES_SPECIAL_REMOTE)
    assert (fn_extracted != fn_in_archive_obscure)
    annex.add(fn_archive)
    annex.commit(msg='Added tarball')
    annex.add(fn_extracted)
    annex.commit(msg='Added the load file')
    annexcr = ArchiveAnnexCustomRemote(annex=None, path=d)
    eq_(annexcr.get_file_url(archive_key='xyz', file='a.dat'), 'dl+archive:xyz#path=a.dat')
    eq_(annexcr.get_file_url(archive_key='xyz', file='a.dat', size=999), 'dl+archive:xyz#path=a.dat&size=999')
    eq_(annexcr._parse_url('dl+archive:xyz/a.dat#size=999'), ('xyz', 'a.dat', {'size': 999}))
    eq_(annexcr._parse_url('dl+archive:xyz/a.dat'), ('xyz', 'a.dat', {}))
    eq_(annexcr._parse_url('dl+archive:xyz#path=a.dat&size=999'), ('xyz', 'a.dat', {'size': 999}))
    eq_(annexcr._parse_url('dl+archive:xyz#path=a.dat'), ('xyz', 'a.dat', {}))
    file_url = annexcr.get_file_url(archive_file=fn_archive, file=((fn_archive.replace('.tar.gz', ) + '/d/') + fn_in_archive_obscure))
    annex.add_url_to_file(fn_extracted, file_url, ['--relaxed'])
    annex.drop(fn_extracted)
    list_of_remotes = annex.whereis(fn_extracted, output='descriptions')
    in_(('[%s]' % ARCHIVES_SPECIAL_REMOTE), list_of_remotes)
    assert_false(annex.file_has_content(fn_extracted))
    with swallow_logs(new_level=logging.INFO) as cml:
        annex.get(fn_extracted)
        cml.assert_logged(msg='datalad-archives special remote is using an extraction', level='INFO', regex=False)
    assert_true(annex.file_has_content(fn_extracted))
    annex.rm_url(fn_extracted, file_url)
    assert_raises(CommandError, annex.drop, fn_extracted)
    annex.add_url_to_file(fn_extracted, file_url)
    annex.drop(fn_extracted)
    annex.get(fn_extracted)
    annex.drop(fn_extracted)
    cloned_annex = AnnexRepo.clone(d, d2)
    assert_false(cloned_annex.file_has_content(fn_archive))
    assert_false(cloned_annex.file_has_content(fn_extracted))
    cloned_annex.get(fn_extracted)
    assert_true(cloned_annex.file_has_content(fn_extracted))
    assert_true(cloned_annex.file_has_content(fn_archive))