in src/buildstream_plugins/sources/docker.py [0:0]
def _get_extract_and_remove_files(layer_tar_path):
"""Return the set of files to remove and extract for a given layer
:param layer_tar_path: The path where a layer has been extracted
:return: Tuple of filesets
- extract_fileset: files to extract into staging directory
- delete_fileset: files to remove from staging directory as the current layer
contains a whiteout corresponding to a staged file in the previous layers
"""
def strip_wh(white_out_file):
"""Strip the prefixing .wh. for given file
:param white_out_file: path of file
:return: path without white-out prefix
"""
# whiteout files have the syntax of `*/.wh.*`
file_name = os.path.basename(white_out_file)
path = os.path.join(os.path.dirname(white_out_file), file_name.split(".wh.")[1])
return path
def is_regular_file(info):
"""Check if file is a non-device file
:param info: tar member metadata
:return: if the file is a non-device file
"""
return not (info.name.startswith("dev/") or info.isdev())
with tarfile.open(layer_tar_path) as tar:
extract_fileset = []
delete_fileset = []
for member in tar.getmembers():
if os.path.basename(member.name).startswith(".wh."):
delete_fileset.append(strip_wh(member.name))
elif is_regular_file(member):
extract_fileset.append(member)
return extract_fileset, delete_fileset