diff mbox series

fetch2: add 'fixperms' option for tar archives with restrictive permissions

Message ID 20260822012007.189830-1-sh0127.shin@lge.com
State New
Headers show
Series fetch2: add 'fixperms' option for tar archives with restrictive permissions | expand

Commit Message

sh0127.shin@lge.com Aug. 22, 2026, 1:20 a.m. UTC
From: "sh0127.shin" <sh0127.shin@lge.com>

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"

Signed-off-by: sh0127.shin <sh0127.shin@lge.com>
---
 lib/bb/fetch2/__init__.py | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index 9cb268be5..1c3bab6d7 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -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)