Handle cross-device renames
authorAlex Chan <alex@alexwlchan.net>
Sat, 28 Nov 2020 23:45:55 +0000 (23:45 +0000)
committerAlex Chan <alex@alexwlchan.net>
Sat, 28 Nov 2020 23:45:55 +0000 (23:45 +0000)
download_overcast_podcasts.py

index 28baf9b..b6f2bfb 100755 (executable)
@@ -19,6 +19,7 @@ import glob
 import itertools
 import json
 import os
+import shutil
 import sqlite3
 import sys
 from urllib.parse import urlparse
@@ -181,7 +182,13 @@ def download_url(*, url, path, description):
         print(f"Error downloading {description}: {err}")
     else:
         print(f"Downloading {description} successful!")
-        os.rename(tmp_path, path)
+        try:
+            os.rename(local_filename, out_path)
+        except OSError as err:
+            if err.errno == errno.EXDEV:
+                shutil.move(local_filename, out_path)
+            else:
+                raise
 
 
 def download_episode(episode, download_dir):