#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import os
import stat
import tarfile
# Without the below statements, tarfile will trigger calls to getpwuid
# and getgrgid for every file extracted. This in turn leads to nscd
# usage which slows down the install phase. Setting these attributes
# to undefined causes tarfile to skip these calls in
# tarfile.gettarinfo(). This information is unnecesary as it will not
# be used by the client.
"""PkgTarFile is a subclass of TarFile. It implements
a small number of additional instance methods to improve
the functionality of the TarFile class for the packaging classes.
XXX - Push these changes upstream to Python maintainers?
"""
"""Extract a member from the TarFile archive. This
method allows you to specify a new filename and path, using
the filename and path arguments, where the file will be
extracted. This method is similar to extract().
Extract() only allows the caller to prepend a directory path
to the filename specified in the TarInfo object,
whereas this method allows the caller to additionally
specify a file name.
"""
else:
tarinfo._link_target = \
if not filename:
# The tarfile we receive contains only files, and none
# of the containing directories. The tarfile code will
# create the directories as necessary, but with mode
# 777, which is insuffficiently secure. Thus we create
# these directories in advance with tighter permissions;
# they'll be fixed up later, when the action execute
# methods run. If proper directory actions
# don't exist for these directories, the permissions
# will be wrong.
try:
except EnvironmentError:
pass
try:
except EnvironmentError as e:
raise
else:
if e.filename is None:
e.strerror))
else:
"tarfile: {0} {1!r}".format(
except tarfile.ExtractError as e:
raise
else: