def test_memory_time_setters(archfmt, timefmt):
    has_birthtime = archfmt != 'zip'

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, archfmt) as archive1:
        archive1.add_files('libarchive/')

    atimestamp = (1482144741, 495628118)
    mtimestamp = (1482155417, 659017086)
    ctimestamp = (1482145211, 536858081)
    btimestamp = (1482144740, 495628118)
    buf2 = bytes(bytearray(1000000))
    with memory_reader(buf) as archive1:
        with memory_writer(buf2, archfmt) as archive2:
            for entry in archive1:
                entry.set_atime(*atimestamp)
                entry.set_mtime(*mtimestamp)
                entry.set_ctime(*ctimestamp)
                if has_birthtime:
                    entry.set_birthtime(*btimestamp)
                archive2.add_entries([entry])

    with memory_reader(buf2) as archive2:
        for entry in archive2:
            assert entry.atime == time_check(atimestamp, timefmt)
            assert entry.mtime == time_check(mtimestamp, timefmt)
            assert entry.ctime == time_check(ctimestamp, timefmt)
            if has_birthtime:
                assert entry.birthtime == time_check(btimestamp, timefmt)
def test_memory_time_setters(archfmt, timefmt):
    has_birthtime = archfmt != 'zip'

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, archfmt) as archive1:
        archive1.add_files('libarchive/')

    atimestamp = (1482144741, 495628118)
    mtimestamp = (1482155417, 659017086)
    ctimestamp = (1482145211, 536858081)
    btimestamp = (1482144740, 495628118)
    buf2 = bytes(bytearray(1000000))
    with memory_reader(buf) as archive1:
        with memory_writer(buf2, archfmt) as archive2:
            for entry in archive1:
                entry.set_atime(*atimestamp)
                entry.set_mtime(*mtimestamp)
                entry.set_ctime(*ctimestamp)
                if has_birthtime:
                    entry.set_birthtime(*btimestamp)
                archive2.add_entries([entry])

    with memory_reader(buf2) as archive2:
        for entry in archive2:
            assert entry.atime == time_check(atimestamp, timefmt)
            assert entry.mtime == time_check(mtimestamp, timefmt)
            assert entry.ctime == time_check(ctimestamp, timefmt)
            if has_birthtime:
                assert entry.birthtime == time_check(btimestamp, timefmt)
Beispiel #3
0
def test_add_files_nonexistent():
    with memory_writer(bytes(bytearray(4096)), 'zip') as archive:
        with pytest.raises(ArchiveError) as e:
            archive.add_files('nonexistent')
        assert e.value.msg
        assert e.value.errno == ENOENT
        assert e.value.retcode == -25
def test_entry_properties():

    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'gnutar') as archive:
        archive.add_files('README.rst')

    readme_stat = stat('README.rst')

    with memory_reader(buf) as archive:
        for entry in archive:
            assert entry.uid == readme_stat.st_uid
            assert entry.gid == readme_stat.st_gid
            assert entry.mode == readme_stat.st_mode
            assert not entry.isblk
            assert not entry.ischr
            assert not entry.isdir
            assert not entry.isfifo
            assert not entry.islnk
            assert not entry.issym
            assert not entry.linkpath
            assert entry.linkpath == entry.linkname
            assert entry.isreg
            assert entry.isfile
            assert not entry.issock
            assert not entry.isdev
            assert b'rw' in entry.strmode
            assert entry.pathname == entry.path
            assert entry.pathname == entry.name
def test_add_files_nonexistent():
    with memory_writer(bytes(bytearray(4096)), 'zip') as archive:
        with pytest.raises(ArchiveError) as e:
            archive.add_files('nonexistent')
        assert e.value.msg
        assert e.value.errno == 2
        assert e.value.retcode == -25
def test_entry_properties():

    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'gnutar') as archive:
        archive.add_files('README.rst')

    readme_stat = stat('README.rst')

    with memory_reader(buf) as archive:
        for entry in archive:
            assert entry.uid == readme_stat.st_uid
            assert entry.gid == readme_stat.st_gid
            assert entry.mode == readme_stat.st_mode
            assert not entry.isblk
            assert not entry.ischr
            assert not entry.isdir
            assert not entry.isfifo
            assert not entry.islnk
            assert not entry.issym
            assert not entry.linkpath
            assert entry.linkpath == entry.linkname
            assert entry.isreg
            assert entry.isfile
            assert not entry.issock
            assert not entry.isdev
            assert b'rw' in entry.strmode
            assert entry.pathname == entry.path
            assert entry.pathname == entry.name
Beispiel #7
0
def test_entry_sparse_manual(tmpdir, sparse_map):
    """ Can we archive a partial non-sparse file as sparse """
    fname = tmpdir.join('sparse1').strpath

    size = 8192
    with open(fname, 'w') as testf:
        testf.write(generate_contents(8192))

    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'pax') as archive:
        with new_archive_entry_from_path(fname) as entry:
            assert len(entry.sparse_map) == 0
            entry.sparse_map.extend(sparse_map)

            # not using archive.add_entries, that assumes the entry comes from
            # another archive and tries to use entry.get_blocks()
            write_p = archive._pointer

            ffi.write_header(write_p, entry.entry_p)

            with open(fname, 'rb') as testf:
                entry_data = testf.read()
                ffi.write_data(write_p, entry_data, len(entry_data))
            ffi.write_finish_entry(write_p)

    with memory_reader(buf) as archive:
        for entry in archive:
            assert entry.name == fname.lstrip('/')
            assert entry.mode == stat(fname)[0]
            assert entry.size == size

            assert len(entry.sparse_map) == len(sparse_map)
            assert entry.sparse_map == sparse_map
def test_entry_properties():

    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'gnutar') as archive:
        archive.add_files('README.rst')

    with memory_reader(buf) as archive:
        for entry in archive:
            assert entry.mode == stat('README.rst')[0]
            assert b'rw' in entry.strmode
def test_convert():

    # Collect information on what should be in the archive
    tree = treestat('libarchive')

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'gnutar', 'xz') as archive1:
        archive1.add_files('libarchive/')

    # Convert the archive to another format
    buf2 = bytes(bytearray(1000000))
    with memory_reader(buf) as archive1:
        with memory_writer(buf2, 'zip') as archive2:
            archive2.add_entries(archive1)

    # Check the data
    with memory_reader(buf2) as archive2:
        check_archive(archive2, tree)
def test_convert():

    # Collect information on what should be in the archive
    tree = treestat('libarchive')

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'gnutar', 'xz') as archive1:
        archive1.add_files('libarchive/')

    # Convert the archive to another format
    buf2 = bytes(bytearray(1000000))
    with memory_reader(buf) as archive1:
        with memory_writer(buf2, 'zip') as archive2:
            archive2.add_entries(archive1)

    # Check the data
    with memory_reader(buf2) as archive2:
        check_archive(archive2, tree)
Beispiel #11
0
def test_entry_properties():

    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'gnutar') as archive:
        archive.add_files('README.rst')

    with memory_reader(buf) as archive:
        for entry in archive:
            assert entry.mode == stat('README.rst')[0]
            assert b'rw' in entry.strmode
Beispiel #12
0
def test_memory_atime_ctime():
    # Collect information on what should be in the archive
    tree = treestat('libarchive', stat_dict)

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'zip') as archive1:
        archive1.add_files('libarchive/')

    # Check the data
    with memory_reader(buf) as archive2:
        check_atime_ctime(archive2, tree)
def test_memory_atime_ctime(archfmt, timefmt):
    # Collect information on what should be in the archive
    tree = treestat('libarchive', stat_dict)

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, archfmt) as archive1:
        archive1.add_files('libarchive/')

    # Check the data
    with memory_reader(buf) as archive2:
        check_atime_ctime(archive2, tree, timefmt=timefmt)
Beispiel #14
0
def test_memory_time_setters():
    # Create an archive of our libarchive/ directory

    atimestamp = (1482144741, 495628118)
    mtimestamp = (1482155417, 659017086)
    ctimestamp = (1482145211, 536858081)
    buf = bytes(bytearray(1000000))
    with memory_writer(buf, "zip") as archive1:
        archive1.add_files('libarchive/')

    buf2 = bytes(bytearray(1000000))
    with memory_reader(buf) as archive1:
        with memory_writer(buf2, "zip") as archive2:
            for entry in archive1:
                entry.set_atime(*atimestamp)
                entry.set_mtime(*mtimestamp)
                entry.set_ctime(*ctimestamp)
                archive2.add_entries([entry])

    with memory_reader(buf2) as archive2:
        for entry in archive2:
            assert entry.atime == atimestamp[0]
            assert entry.mtime == mtimestamp[0]
            assert entry.ctime == ctimestamp[0]
Beispiel #15
0
def test_entry_sparse(tmpdir, size, write_map, sparse_map):
    """ Test that we can write & read back a sparse file and the sparse map """
    fname = tmpdir.join('sparse1').strpath

    create_sparse_file(fname, write_map, size)

    buf = bytes(bytearray(1000000))
    with memory_writer(buf, 'pax') as archive:
        archive.add_files(fname)

    with memory_reader(buf) as archive:
        for entry in archive:
            assert entry.name == fname.lstrip('/')
            assert entry.mode == stat(fname)[0]
            assert entry.size == size

            assert len(entry.sparse_map) == len(sparse_map)
            assert entry.sparse_map == sparse_map
def test_buffers(tmpdir):

    # Collect information on what should be in the archive
    tree = treestat('libarchive')

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with libarchive.memory_writer(buf, 'gnutar', 'xz') as archive:
        archive.add_files('libarchive/')

    # Read the archive and check that the data is correct
    with libarchive.memory_reader(buf) as archive:
        check_archive(archive, tree)

    # Extract the archive in tmpdir and check that the data is intact
    with in_dir(tmpdir.strpath):
        flags = EXTRACT_OWNER | EXTRACT_PERM | EXTRACT_TIME
        libarchive.extract_memory(buf, flags)
        tree2 = treestat('libarchive')
        assert tree2 == tree
Beispiel #17
0
def test_buffers(tmpdir):

    # Collect information on what should be in the archive
    tree = treestat('libarchive')

    # Create an archive of our libarchive/ directory
    buf = bytes(bytearray(1000000))
    with libarchive.memory_writer(buf, 'gnutar', 'xz') as archive:
        archive.add_files('libarchive/')

    # Read the archive and check that the data is correct
    with libarchive.memory_reader(buf) as archive:
        check_archive(archive, tree)

    # Extract the archive in tmpdir and check that the data is intact
    with in_dir(tmpdir.strpath):
        flags = EXTRACT_OWNER | EXTRACT_PERM | EXTRACT_TIME
        libarchive.extract_memory(buf, flags)
        tree2 = treestat('libarchive')
        assert tree2 == tree