Using tar option strip-components in do_unpack
Hi,
I discussed with pb on irc, how it would be the best way to unpack two tar archivs into the same directory. He pointed me to the tar strip-components options and attached is the outcome. Because base.bbclass is touched it is open for discussion here.
Bye Henning
From 0688f07fe2e8b1926ae1dc34a03d6b5845871f74 Mon Sep 17 00:00:00 2001
From: Henning Heinold <[email protected]>
Date: Fri, 14 May 2010 21:16:30 +0200
Subject: [PATCH] base.bbclass: introduce strip-components option for tar and set tar
options in a sane way
* you can use now the following in your SRC_URI to munge diffrent tar archivs into the same directory
http://foo.tar.bz2;strip_components=1;subdir=foo \
http://foo2.tar.bz2;strip_components=1;subdir=foo
--- classes/base.bbclass | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-)
classes/base.bbclass +10 -5
@@ -171,18 +171,24 @@ def oe_unpack_file(file, data, url = None): else: efile = file cmd = None + tar_options = 'x --no-same-owner' + parm = bb.decodeurl(url)[5] + if 'strip_components' in parm: + bb.note("using strip_componetes") + tar_options = tar_options + ' --strip-components=%s' % parm['strip_components'] + tar_options = tar_options + ' -f' if file.endswith('.tar'): - cmd = 'tar x --no-same-owner -f %s' % file + cmd = 'tar %s %s' % (tar_options, file) elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'): - cmd = 'tar xz --no-same-owner -f %s' % file + cmd = 'tar z%s %s' % (tar_options, file) elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'): - cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file + cmd = 'bzip2 -dc %s | tar %s -' % (file, tar_options) elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'): cmd = 'gzip -dc %s > %s' % (file, efile) elif file.endswith('.bz2'): cmd = 'bzip2 -dc %s > %s' % (file, efile) elif file.endswith('.tar.xz'): - cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file + cmd = 'xz -dc %s | tar %s -' % (file, tar_options) elif file.endswith('.xz'): cmd = 'xz -dc %s > %s' % (file, efile) elif file.endswith('.zip') or file.endswith('.jar'):
@@ -227,7 +233,6 @@ def oe_unpack_file(file, data, url = None): # Change to subdir before executing command save_cwd = os.getcwd(); - parm = bb.decodeurl(url)[5] if 'subdir' in parm: newdir = ("%s/%s" % (os.getcwd(), parm['subdir'])) bb.mkdirhier(newdir)
Signature · 1 line
1.7.1
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 6 lines · Henning Heinold
Hi,
I discussed with pb on irc, how it would be the best way to unpack two tar archivs into the same directory. He pointed me to the tar strip-components options and attached is the outcome. Because base.bbclass is touched it is open for discussion here.
Please don't forget to update docs/usermanual when adding new features.
regards,
Koen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFL7k88MkyGM64RGpERAoP/AJ0fMfFBe9tU9EVo0OWwPIgX2O/28ACeMRNC YG2B3XCuKE7FQeHnAEBKZ64=
=bF/F
-----END PGP SIGNATURE-----
classes/base.bbclass def oe_unpack_file(file, data, url = None): · line 181
Quoted 9 lines · Henning Heinold
I discussed with pb on irc, how it would be the best way to unpack two tar archivs into the same directory. He pointed me to the tar strip-components options and attached is the outcome. Because base.bbclass is touched it is open for discussion here.
classes/base.bbclass +2
-1+ tar_options = tar_options + ' -f' if file.endswith('.tar'): - cmd = 'tar x --no-same-owner -f %s' % file + cmd = 'tar %s %s' % (tar_options, file)
I think it would be a good idea to try to keep "-f" and the filename together, rather than splitting them across two strings. It isn't completely obvious to someone looking at this code that "-f" needs to be the last thing in tar_options and that the filename needs to follow it immediately.
So, I suggest not adding -f to tar_options and instead doing something like:
cmd = 'tar %s -f %s' % (tar_options, file)
Apart from that I think your patch is good. Thanks for looking at this.
p.