in aws_lambda_builders/workflows/dotnet_clipackage/utils.py [0:0]
def _extract(self, file_info, output_dir, zip_ref):
"""
Unzip the given file into the given directory while preserving file permissions in the process.
Parameters
----------
file_info : zipfile.ZipInfo
The ZipInfo for a ZipFile
output_dir : str
Path to the directory where the it should be unzipped to
zip_ref : zipfile.ZipFile
The ZipFile we are working with.
Returns
-------
string
Returns the target path the Zip Entry was extracted to.
"""
# Handle any regular file/directory entries
if not self._is_symlink(file_info):
return zip_ref.extract(file_info, output_dir)
source = decode(zip_ref.read(file_info.filename))
link_name = os.path.normpath(os.path.join(output_dir, file_info.filename))
# make leading dirs if needed
leading_dirs = os.path.dirname(link_name)
if not os.path.exists(leading_dirs):
os.makedirs(leading_dirs)
# If the link already exists, delete it or symlink() fails
if os.path.lexists(link_name):
os.remove(link_name)
# Create a symbolic link pointing to source named link_name.
os.symlink(source, link_name)
return link_name