#2461 cli: delete downloaded file with zero size
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue2451  into  master

file modified
+21 -16
@@ -525,22 +525,27 @@ 

          # rewrite

          f = open(relpath, 'wb')

  

-     # closing needs to be used for requests < 2.18.0

-     with closing(requests.get(url, headers=headers, stream=True)) as response:

-         if response.status_code in (200, 416):  # full content provided or reaching behing EOF

-             # rewrite in such case

-             f.close()

-             f = open(relpath, 'wb')

-         response.raise_for_status()

-         length = filesize or int(response.headers.get('content-length') or 0)

-         for chunk in response.iter_content(chunk_size=1024**2):

-             pos += len(chunk)

-             f.write(chunk)

-             if not (quiet or noprogress):

-                 _download_progress(length, pos, filesize)

-         if not length and not (quiet or noprogress):

-             _download_progress(pos, pos, filesize)

-     f.close()

+     try:

+         # closing needs to be used for requests < 2.18.0

+         with closing(requests.get(url, headers=headers, stream=True)) as response:

+             if response.status_code in (200, 416):  # full content provided or reaching behind EOF

+                 # rewrite in such case

+                 f.close()

+                 f = open(relpath, 'wb')

+             response.raise_for_status()

+             length = filesize or int(response.headers.get('content-length') or 0)

+             for chunk in response.iter_content(chunk_size=1024**2):

+                 pos += len(chunk)

+                 f.write(chunk)

+                 if not (quiet or noprogress):

+                     _download_progress(length, pos, filesize)

+             if not length and not (quiet or noprogress):

+                 _download_progress(pos, pos, filesize)

+     finally:

+         f.close()

+         if pos == 0:

+             # nothing was downloaded, e.g file not found

+             os.unlink(relpath)

  

      if not (quiet or noprogress):

          print('')

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

2 years ago

rebased onto dbd0c9a

2 years ago

Commit 20ada32 fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago