Merge ~racb/ubuntu-dev-tools:diff-gz-identity into ubuntu-dev-tools:main

Proposed by Robie Basak
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 4bcc55372a663da0d61b4041f3c26a09a9a3c964
Merged at revision: 4bcc55372a663da0d61b4041f3c26a09a9a3c964
Proposed branch: ~racb/ubuntu-dev-tools:diff-gz-identity
Merge into: ubuntu-dev-tools:main
Diff against target: 58 lines (+22/-4)
2 files modified
debian/changelog (+7/-2)
ubuntutools/misc.py (+15/-2)
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+446078@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote :

I force pushed to add some comments.

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, the explanations on the bug are convincing to me and the code changes match what was described (+bonus points for documenting the reason)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 64c7284..7b1618f 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,11 +1,16 @@
6-ubuntu-dev-tools (0.193ubuntu5) UNRELEASED; urgency=medium
7+ubuntu-dev-tools (0.193ubuntu5) mantic; urgency=medium
8
9+ [ Steve Langasek ]
10 * Remove references to deprecated
11 http://people.canonical.com/~ubuntu-archive.
12 * Remove references to architectures not supported in any active
13 Ubuntu release.
14
15- -- Steve Langasek <steve.langasek@ubuntu.com> Tue, 30 May 2023 19:35:57 -0700
16+ [ Robie Basak ]
17+ * ubuntutools/misc: swap iter_content for raw stream with "Accept-Encoding:
18+ identity" to fix .diff.gz downloads (LP: #2025748).
19+
20+ -- Robie Basak <robie.basak@ubuntu.com> Wed, 05 Jul 2023 15:32:43 +0100
21
22 ubuntu-dev-tools (0.193ubuntu4) mantic; urgency=medium
23
24diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py
25index 3f8f70e..0b31e42 100644
26--- a/ubuntutools/misc.py
27+++ b/ubuntutools/misc.py
28@@ -348,7 +348,11 @@ def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
29 with tempfile.TemporaryDirectory() as tmpdir:
30 tmpdst = Path(tmpdir) / "dst"
31 try:
32- with requests.get(src, stream=True, timeout=60, auth=auth) as fsrc:
33+ # We must use "Accept-Encoding: identity" so that Launchpad doesn't
34+ # compress changes files. See LP: #2025748.
35+ with requests.get(
36+ src, stream=True, timeout=60, auth=auth, headers={"accept-encoding": "identity"}
37+ ) as fsrc:
38 with tmpdst.open("wb") as fdst:
39 fsrc.raise_for_status()
40 _download(fsrc, fdst, size, blocksize=blocksize)
41@@ -433,7 +437,16 @@ def _download(fsrc, fdst, size, *, blocksize):
42
43 downloaded = 0
44 try:
45- for block in fsrc.iter_content(blocksize):
46+ while True:
47+ # We use fsrc.raw so that compressed files stay compressed as we
48+ # write them to disk. For example, if this is a .diff.gz, then it
49+ # needs to remain compressed and unmodified to remain valid as part
50+ # of a source package later, even though Launchpad sends
51+ # "Content-Encoding: gzip" and the requests library therefore would
52+ # want to decompress it. See LP: #2025748.
53+ block = fsrc.raw.read(blocksize)
54+ if not block:
55+ break
56 fdst.write(block)
57 downloaded += len(block)
58 progress_bar.update(downloaded, size)

Subscribers

People subscribed via source and target branches