diff options
author | Googler <noreply@google.com> | 2015-11-16 23:16:41 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-11-17 10:52:54 +0000 |
commit | 1648470c7fe1048e23fadcd02d6e81c693f52259 (patch) | |
tree | 759ae536835f05ab910914989d12fc86c6363383 /tools/build_defs/pkg/archive.py | |
parent | e5fc3ae790812920fe5d7cfa65b0e6157d38e46e (diff) |
Apply the docker_build directory option to tars as well as files.
* It enables tar packages to be placed at "/usr/local", say, and removes
the need for the current workaround of repackaging the original tars.
--
MOS_MIGRATED_REVID=107983091
Diffstat (limited to 'tools/build_defs/pkg/archive.py')
-rw-r--r-- | tools/build_defs/pkg/archive.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tools/build_defs/pkg/archive.py b/tools/build_defs/pkg/archive.py index 6fd1916a17..6660663c41 100644 --- a/tools/build_defs/pkg/archive.py +++ b/tools/build_defs/pkg/archive.py @@ -275,7 +275,8 @@ class TarFileWriter(object): rootuid=None, rootgid=None, numeric=False, - name_filter=None): + name_filter=None, + root=None): """Merge a tar content into the current tar, stripping timestamp. Args: @@ -287,6 +288,8 @@ class TarFileWriter(object): name_filter: filter out file by names. If not none, this method will be called for each file to add, given the name and should return true if the file is to be added to the final tar and false otherwise. + root: place all non-absolute content under given root direcory, if not + None. """ compression = os.path.splitext(tar)[-1][1:] if compression == 'tgz': @@ -321,9 +324,28 @@ class TarFileWriter(object): if numeric: tarinfo.uname = '' tarinfo.gname = '' + name = tarinfo.name if not name.startswith('/') and not name.startswith('.'): - tarinfo.name = './' + name + name = './' + name + if root is not None: + if name.startswith('.'): + name = '.' + root + name.lstrip('.') + # Add root dir with same permissions if missing. Note that + # add_file deduplicates directories and is safe to call here. + self.add_file('.' + root, + tarfile.DIRTYPE, + uid=tarinfo.uid, + gid=tarinfo.gid, + uname=tarinfo.uname, + gname=tarinfo.gname, + mtime=tarinfo.mtime, + mode=0755) + # Relocate internal hardlinks as well to avoid breaking them. + link = tarinfo.linkname + if link.startswith('.') and tarinfo.type == tarfile.LNKTYPE: + tarinfo.linkname = '.' + root + link.lstrip('.') + tarinfo.name = name if tarinfo.isfile(): self._addfile(tarinfo, intar.extractfile(tarinfo.name)) |