]> jfr.im git - yt-dlp.git/commitdiff
[update] Fix updater removing the executable bit on some UNIX distros
authorpukkandan <redacted>
Wed, 3 Mar 2021 13:26:33 +0000 (18:56 +0530)
committerpukkandan <redacted>
Wed, 3 Mar 2021 13:37:14 +0000 (19:07 +0530)
Closes #133

yt_dlp/update.py

index 5ae4e52049046801264de563c5584bd8d441b138..c773e272141fc7474155be2cb3b180acd102b468 100644 (file)
@@ -197,28 +197,18 @@ def get_sha256sum(bin_or_exe, version):
             to_screen('Visit https://github.com/yt-dlp/yt-dlp/releases/latest')
             return
 
-        try:
-            with open(filename + '.new', 'wb') as outf:
-                outf.write(newcontent)
-        except (IOError, OSError):
-            if verbose:
-                to_screen(encode_compat_str(traceback.format_exc()))
-            to_screen('ERROR: unable to write the new version')
-            return
-
         expected_sum = get_sha256sum('zip', py_ver)
-        if expected_sum and calc_sha256sum(filename + '.new') != expected_sum:
+        if expected_sum and hashlib.sha256(newcontent).hexdigest() != expected_sum:
             to_screen('ERROR: unable to verify the new zip')
             to_screen('Visit https://github.com/yt-dlp/yt-dlp/releases/latest')
-            try:
-                os.remove(filename + '.new')
-            except OSError:
-                to_screen('ERROR: unable to remove corrupt zip')
             return
 
         try:
-            os.rename(filename + '.new', filename)
-        except OSError:
+            with open(filename, 'wb') as outf:
+                outf.write(newcontent)
+        except (IOError, OSError):
+            if verbose:
+                to_screen(encode_compat_str(traceback.format_exc()))
             to_screen('ERROR: unable to overwrite current version')
             return