瀏覽代碼

[abfs] Fix isdir and isfile methods to handle exceptions better (#4002)

Add try/except block to correctly catch ABFS exceptions and then handle the 404 case explicitly to determine if the path exists or not.
Harsh Gupta 9 月之前
父節點
當前提交
24f50679aa
共有 1 個文件被更改,包括 18 次插入9 次删除
  1. 18 9
      desktop/libs/azure/src/azure/abfs/abfs.py

+ 18 - 9
desktop/libs/azure/src/azure/abfs/abfs.py

@@ -143,17 +143,26 @@ class ABFS(object):
   # Parse info about filesystems, directories, and files
   # Parse info about filesystems, directories, and files
   # --------------------------------
   # --------------------------------
   def isdir(self, path):
   def isdir(self, path):
-    """
-    Checks if the path is a directory (note diabled because filebrowser/views is bugged)
-    """
-    resp = self.stats(path)
-    return resp.isDir
+    """Check if the given path is a directory or not."""
+    try:
+      stats = self.stats(path)
+      return stats.isDir
+    except Exception as e:
+      # If checking stats for path here gives 404 error, it means the path does not exist and therefore is not a directory.
+      if e.code == 404:
+        return False
+      raise e
 
 
   def isfile(self, path):
   def isfile(self, path):
-    """
-    Checks if the path is a file
-    """
-    return not self.isdir(path)
+    """Check if the given path is a file or not."""
+    try:
+      stats = self.stats(path)
+      return not stats.isDir
+    except Exception as e:
+      # If checking stats for path here gives 404 error, it means the path does not exist and therefore is not a file.
+      if e.code == 404:
+        return False
+      raise e
 
 
   def exists(self, path):
   def exists(self, path):
     """
     """