← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:oci-fileno-error-on-upload into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:oci-fileno-error-on-upload into launchpad:master.

Commit message:
Workaround requests handling of extract tar files

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/399644

Requests doesn't like extracted tar files, as they have a 'fileno' attribute, but accessing it causes an error.
Upstream requests PR is here: https://github.com/psf/requests/pull/5239

For now, just give the layer object a len (set to tarfile.size).
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:oci-fileno-error-on-upload into launchpad:master.
diff --git a/lib/lp/oci/model/ociregistryclient.py b/lib/lp/oci/model/ociregistryclient.py
index 1a9be6c..f1e083b 100644
--- a/lib/lp/oci/model/ociregistryclient.py
+++ b/lib/lp/oci/model/ociregistryclient.py
@@ -167,6 +167,10 @@ class OCIRegistryClient:
                     if tarinfo.name != 'layer.tar':
                         continue
                     fileobj = un_zipped.extractfile(tarinfo)
+                    # XXX Work around requests handling of objects that have
+                    # fileno, but error on access in python3:
+                    # https://github.com/psf/requests/pull/5239
+                    fileobj.len = tarinfo.size
                     try:
                         cls._upload(
                             digest, push_rule, fileobj, tarinfo.size,