[issue10760] tarfile doesn't handle sysfs well

Guy Rozendorn report at bugs.python.org
Mon Sep 24 03:53:53 CEST 2012


Guy Rozendorn added the comment:

Here's a test case that re-creates this issue.
I chose to use mocks instead of sample files from sysfs so it would be simpler to run, it can be easily changed to use a file from sysfs.

The following code runs on Python2.7, requires the mock library

{code}
from unittest import TestCase
from tempfile import mkstemp
from mock import patch, Mock
from os import close, remove, write, stat
from posix import stat_result
from tarfile import TarFile

def fake_st_size_side_effect(*args, **kwargs):
    src, = args
    stats = stat(src)
    return stat_result((stats.st_mode, stats.st_ino, stats.st_dev, stats.st_nlink,
                       stats.st_uid, stats.st_gid, stats.st_size + 10,
                       stats.st_atime, stats.st_mtime, stats.st_ctime))

class Issue10760TestCase(TestCase):
    def setUp(self):
        fd, self.src = mkstemp()
        write(fd, '\x00' * 4)
        close(fd)
        fd, self.dst = mkstemp()
        close(fd)

    def test(self):
        with patch("os.lstat") as lstat:
            lstat.side_effect = fake_st_size_side_effect
            tar_file = TarFile.open(self.dst, 'w:gz')
            tar_file.add(self.src)

{code}

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10760>
_______________________________________


More information about the Python-bugs-list mailing list