MCPcopy Index your code
hub / github.com/astral-sh/python-build-standalone / container_get_archive

Function container_get_archive

pythonbuild/docker.py:157–177  ·  view source on GitHub ↗

Get a deterministic tar archive from a container.

(container, path)

Source from the content-addressed store, hash-verified

155
156
157def container_get_archive(container, path):
158 """Get a deterministic tar archive from a container."""
159 data, stat = container.get_archive(path)
160 old_data = io.BytesIO()
161 for chunk in data:
162 old_data.write(chunk)
163
164 old_data.seek(0)
165
166 new_data = io.BytesIO()
167
168 with (
169 tarfile.open(fileobj=old_data) as itf,
170 tarfile.open(fileobj=new_data, mode="w") as otf,
171 ):
172 for member in sorted(itf.getmembers(), key=operator.attrgetter("name")):
173 file_data = itf.extractfile(member) if not member.linkname else None
174 member.mtime = DEFAULT_MTIME
175 otf.addfile(member, file_data)
176
177 return new_data.getvalue()

Callers 3

get_tools_archiveMethod · 0.85
get_fileMethod · 0.85
get_output_archiveMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected