Get a deterministic tar archive from a container.
(container, path)
| 155 | |
| 156 | |
| 157 | def 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() |
no outgoing calls
no test coverage detected