Ejemplo n.º 1
0
    def test_extract_utf8(self):

        tmpdir = tempfile.mkdtemp()

        testarchivepath = os.path.join(
            self.testdirectory, 'testdata', 'tešt.tar'
        )

        LibArchive.extract(
            self.testcontainer,
            container(testarchivepath).archive,
            tmpdir
        )

        n = 0
        for prefix, files, dirs in os.walk(tmpdir):
            n += len(files) + len(dirs)

        self.assertEqual(n, 1)
        self.assertTrue(os.path.exists(os.path.join(tmpdir, 'tarmanš.log')))

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 2
0
    def test_corrupted_extract_selective(self):

        path1 = self.corruptedarchivepath

        checked = DirectoryTree(
            self.corruptedarchivepath,
            self.testcontainer
        )
        checked.add(path1, True)

        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(
            self.testcontainer,
            container(self.corruptedarchivepath).archive,
            tmpdir,
            checked
        )

        n = 0
        for prefix, files, dirs in os.walk(tmpdir):
            n += len(files) + len(dirs)

        self.assertEqual(n, 0)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 3
0
    def test_corrupted_create(self):

        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(self.testcontainer,
                           container(self.corruptedarchivepath).archive,
                           tmpdir)

        fs = FileSystem()
        path1 = tmpdir

        checked = DirectoryTree(tmpdir, fs)
        checked.add(path1, True)

        corrupted2archivepath = os.path.join(tmpdir, 'corrupted2.tar')

        LibArchive.create(fs, corrupted2archivepath, checked)

        self.assertTrue(os.path.exists(corrupted2archivepath))

        corrupted2archive = LibArchive(corrupted2archivepath)
        self.assertEqual(len(corrupted2archive.tree.root.children), 0)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 4
0
    def test_corrupted_extract_selective(self):

        path1 = self.corruptedarchivepath

        checked = DirectoryTree(self.corruptedarchivepath, self.testcontainer)
        checked.add(path1, True)

        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(self.testcontainer,
                           container(self.corruptedarchivepath).archive,
                           tmpdir, checked)

        n = 0
        for prefix, files, dirs in os.walk(tmpdir):
            n += len(files) + len(dirs)

        self.assertEqual(n, 0)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 5
0
    def test_create_utf8(self):

        tmpdir = tempfile.mkdtemp()

        testarchivepath = os.path.join(self.testdirectory, 'testdata',
                                       'tešt.tar')

        LibArchive.extract(self.testcontainer,
                           container(testarchivepath).archive, tmpdir)

        path1 = os.path.join(tmpdir, 'tarmanš.log')
        fs = FileSystem()

        checked = DirectoryTree(tmpdir, fs)
        checked.add(path1, False)

        testdata2archivepath = os.path.join(tmpdir, 'tešt2.tar')

        LibArchive.create(fs, testdata2archivepath, checked)

        self.assertTrue(os.path.exists(testdata2archivepath))

        testdata2archive = LibArchive(testdata2archivepath)
        apath1 = os.path.join(testdata2archivepath, 'tarmanš.log')
        self.assertIn(apath1, testdata2archive.tree)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 6
0
    def test_create_utf8(self):

        tmpdir = tempfile.mkdtemp()

        testarchivepath = os.path.join(
            self.testdirectory, 'testdata', 'tešt.tar'
        )

        LibArchive.extract(
            self.testcontainer,
            container(testarchivepath).archive,
            tmpdir
        )

        path1 = os.path.join(tmpdir, 'tarmanš.log')
        fs = FileSystem()

        checked = DirectoryTree(
            tmpdir,
            fs
        )
        checked.add(path1, False)

        testdata2archivepath = os.path.join(
            tmpdir, 'tešt2.tar'
        )

        LibArchive.create(
            fs,
            testdata2archivepath,
            checked
        )

        self.assertTrue(os.path.exists(testdata2archivepath))

        testdata2archive = LibArchive(testdata2archivepath)
        apath1 = os.path.join(testdata2archivepath, 'tarmanš.log')
        self.assertIn(apath1, testdata2archive.tree)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 7
0
    def test_corrupted_extract_all(self):
        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(self.testcontainer,
                           container(self.corruptedarchivepath).archive,
                           tmpdir)

        n = 0
        for prefix, files, dirs in os.walk(tmpdir):
            n += len(files) + len(dirs)

        self.assertEqual(n, 1)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 8
0
    def test_corrupted_create(self):

        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(
            self.testcontainer,
            container(self.corruptedarchivepath).archive,
            tmpdir
        )

        fs = FileSystem()
        path1 = tmpdir

        checked = DirectoryTree(
            tmpdir,
            fs
        )
        checked.add(path1, True)

        corrupted2archivepath = os.path.join(
            tmpdir, 'corrupted2.tar'
        )

        LibArchive.create(
            fs,
            corrupted2archivepath,
            checked
        )

        self.assertTrue(os.path.exists(corrupted2archivepath))

        corrupted2archive = LibArchive(corrupted2archivepath)
        self.assertEqual(len(corrupted2archive.tree.root.children), 0)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 9
0
    def test_corrupted_extract_all(self):
        tmpdir = tempfile.mkdtemp()

        LibArchive.extract(
            self.testcontainer,
            container(self.corruptedarchivepath).archive,
            tmpdir
        )

        n = 0
        for prefix, files, dirs in os.walk(tmpdir):
            n += len(files) + len(dirs)

        self.assertEqual(n, 1)

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)
Ejemplo n.º 10
0
    def test_extract_utf8(self):

        tmpdir = tempfile.mkdtemp()

        testarchivepath = os.path.join(self.testdirectory, 'testdata',
                                       'tešt.tar')

        LibArchive.extract(self.testcontainer,
                           container(testarchivepath).archive, tmpdir)

        n = 0
        for prefix, files, dirs in os.walk(tmpdir):
            n += len(files) + len(dirs)

        self.assertEqual(n, 1)
        self.assertTrue(os.path.exists(os.path.join(tmpdir, 'tarmanš.log')))

        # clean up
        for root, dirs, files in os.walk(tmpdir, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        os.rmdir(tmpdir)