fetch2: add 'fixperms' option for tar archives with restrictive permissions
PATCH 1/1 fetch2: add 'fixperms' option for tar archives with restrictive permissions
From: "sh0127.shin" <[email protected]>
Some tar archives contain directories with restrictive permissions (e.g. drw-r--r--) that can prevent extraction or subsequent processing from completing successfully.
Extend FetchMethod.unpack() with a new 'fixperms' SRC_URI parameter.
When 'fixperms=1' is specified:
1. Add --delay-directory-restore to the tar command to defer directory permission restoration until all contents are extracted.
2. Apply chmod -R +X after extraction to ensure directories remain traversable and executable files retain appropriate execute permissions.
Usage:
SRC_URI = "https://example.com/foo.tgz;fixperms=1"
--- lib/bb/fetch2/__init__.py | 5 +++++ 1 file changed, 5 insertions(+)
lib/bb/fetch2/__init__.py +5 -0
@@ -1564,6 +1564,8 @@ class FetchMethod(object): if unpack: tar_cmd = ['tar', '--extract', '--no-same-owner'] + if 'fixperms' in urldata.parm and urldata.parm['fixperms'] == '1': + tar_cmd.append('--delay-directory-restore') if 'striplevel' in urldata.parm: striplevel = urldata.parm['striplevel'] if not striplevel.isdigit():
@@ -1659,6 +1661,9 @@ class FetchMethod(object): bb.note("Unpacking %s to %s/" % (file, unpackdir)) _run(cmd) + if 'fixperms' in urldata.parm and urldata.parm['fixperms'] == '1': + _run(['chmod', '-R', '+X', unpackdir]) + if iterate is True: iterate_urldata = urldata iterate_urldata.localpath = "%s/%s" % (rootdir, iterate_file)
Signature · 1 line
2.34.1
PATCH 2/2 fetch2/tests: add test for fixperms option
From: "sh0127.shin" <[email protected]>
Add a unit test for the 'fixperms' SRC_URI parameter introduced in FetchMethod.unpack().
The test creates a tar.gz archive containing a directory with restrictive permissions (0o644, no execute bit), then verifies that unpacking with fixperms=1:
1. Successfully extracts files inside the restrictive directory.
2. Restores the execute bit on the directory via chmod -R +X.
--- lib/bb/tests/fetch.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
lib/bb/tests/fetch.py +31 -0
@@ -876,6 +876,37 @@ class FetcherLocalTest(FetcherTest): with self.subTest(striplevel=repr(value)): self.assertInvalidStriplevel(value) + def test_local_fixperms(self): + """Test that fixperms=1 allows extraction of archives with restrictive directory permissions""" + import tarfile + import stat + + # Create a tar archive with a directory having restrictive permissions (drw-r--r--) + archive_path = os.path.join(self.localsrcdir, 'archive_fixperms.tar.gz') + with tarfile.open(archive_path, 'w:gz') as tar: + # Add a directory with no execute bit (0o644) + dirinfo = tarfile.TarInfo(name='restrictive_dir') + dirinfo.type = tarfile.DIRTYPE + dirinfo.mode = 0o644 + tar.addfile(dirinfo) + # Add a file inside the restrictive directory + import io + content = b'test content' + fileinfo = tarfile.TarInfo(name='restrictive_dir/testfile.txt') + fileinfo.size = len(content) + fileinfo.mode = 0o644 + tar.addfile(fileinfo, io.BytesIO(content)) + + # Without fixperms, extraction may fail or leave inaccessible dirs + # With fixperms=1, chmod -R +X is applied after extraction + tree = self.fetchUnpack(['file://archive_fixperms.tar.gz;fixperms=1']) + self.assertIn('restrictive_dir/testfile.txt', tree) + + # Verify directory is traversable after fixperms + dirpath = os.path.join(self.unpackdir, 'restrictive_dir') + dirstat = os.stat(dirpath) + self.assertTrue(dirstat.st_mode & stat.S_IXUSR, "Directory should have execute bit after fixperms") + def dummyGitTest(self, suffix): # Create dummy local Git repo src_dir = tempfile.mkdtemp(dir=self.tempdir,
Signature · 1 line
2.34.1
Quoted 3 lines · On Sat, 22 Aug 2026 at 03:20, sh0127shin via lists.openembedded.org…
Some tar archives contain directories with restrictive permissions (e.g. drw-r--r--) that can prevent extraction or subsequent processing from completing successfully.
Hello,
I think this can be solved by adding unpack=0 to SRC_URI, and then adding a custom task that runs between unpack and patch that extracts the tarball with a special procedure. Tarballs can contains all kinds of esoteric problems like this one, I don't think bitbake should try to accommodate them.
Alex