瀏覽代碼

cath long filename error in BTR downloading

Johannes Gütschow 3 月之前
父節點
當前提交
311face2c7
共有 1 個文件被更改,包括 15 次插入5 次删除
  1. 15 5
      src/unfccc_ghg_data/unfccc_downloader/download_btr.py

+ 15 - 5
src/unfccc_ghg_data/unfccc_downloader/download_btr.py

@@ -97,11 +97,21 @@ if __name__ == "__main__":
         if not local_filename.parent.exists():
             local_filename.parent.mkdir()
 
-        if local_filename.exists():
-            # check file size. if 210 or 212 bytes it's the error page
-            if Path(local_filename).stat().st_size in error_file_sizes:
-                # found the error page. delete file
-                os.remove(local_filename)
+        try:
+            if local_filename.exists():
+                # check file size. if 210 or 212 bytes it's the error page
+                if Path(local_filename).stat().st_size in error_file_sizes:
+                    # found the error page. delete file
+                    os.remove(local_filename)
+        except OSError as ex:
+            if ex.errno == 36:  # noqa: PLR2004
+                print(
+                    f"Filename is too long: "
+                    f"{local_filename.relative_to(root_path)}. "
+                    f" Message: {ex}"
+                )
+            else:
+                raise
 
         # now we have removed error pages, so a present file should not be overwritten
         if (not local_filename.exists()) and (not local_filename.is_symlink()):