Bug 1492157

Summary: [RFE] tarfile: add an option to change the "blocking factor"
Product: Red Hat Enterprise Linux 7 Reporter: Simone Tiraboschi <stirabos>
Component: pythonAssignee: Python Maintainers <python-maint>
Status: CLOSED WONTFIX QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.4CC: cstratak, hhorak, jkejda, pviktori, vstinner
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-08-02 13:36:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1480039    

Description Simone Tiraboschi 2017-09-15 15:52:24 UTC
Description of problem:
According to tar man page:

Device blocking:
       -b, --blocking-factor=BLOCKS
              BLOCKS x 512 bytes per record

and tar will read and write entire records.

According to tarfile documentation,

tarfile.open(name=None, mode=’r’, fileobj=None, bufsize=10240, **kwargs)
...
bufsize specifies the blocksize and defaults to 20 * 512 bytes

but if I try creating an archive specifying a different blocking factor, tarfile simply ignores and keeps 10240.

The issue can be easily reproduced with this snippet:

    import os
    import tarfile
    import tempfile
    
    EXPECTED_SIZE = 20480
    tempdir = tempfile.gettempdir()
    fd, _tmp_tar = tempfile.mkstemp(
        suffix='.tar',
        dir=tempdir,
    )
    os.close(fd)
    tar = tarfile.open(name=_tmp_tar, mode='w', bufsize=EXPECTED_SIZE)
    tar.close()
    statinfo = os.stat(_tmp_tar)
    if statinfo.st_size != EXPECTED_SIZE:
        raise RuntimeError((
            'Archive size doens\'t match expected size: '
            'actual {a} - expected {e}'
        ).format(
            a=statinfo.st_size,
            e=EXPECTED_SIZE,
        ))


Version-Release number of selected component (if applicable):


How reproducible:
python-libs-2.7.5-58.el7.x86_64

Steps to Reproduce:
1. try creating an archive with a custom blocking factor
2.
3.

Actual results:
tarfile.open ignores and keeps 10240 (the default value)

Expected results:
tarfile.open honors the custom blocking factor

Additional info:

    tar --blocking-factor=40 -cf test.tar -T /dev/null

works as expected creating an empty tar archive of 20480 (40x512) bytes.

Comment 2 Petr Viktorin (pviktori) 2017-10-05 13:41:46 UTC
This is on our radar but we're not sure if we can fit investigating it in the 7.5 devel phase.
Let me know if this is higher priority.

Comment 5 Petr Viktorin (pviktori) 2018-04-11 10:18:44 UTC
This is still low priority, let us know if it needs attention now.

Comment 6 Petr Viktorin (pviktori) 2018-06-07 14:16:57 UTC
Victor, this is low priority, but one of the things that could use a core dev's attention.

Comment 7 Victor Stinner 2018-06-20 13:06:34 UTC
Sadly, in Python, it's not possible to configure the blocking factor. The bufsize parameter is just an optimization for internal data copies, it's unrelated to the blocking factor. I updated the upstream issue as a feature request: https://bugs.python.org/issue31774

Comment 9 Petr Viktorin (pviktori) 2018-08-02 13:36:19 UTC
We will not fix this in Python 2.
Please re-open if that's a problem.