JatinAutonomousLabs commited on
Commit
2dd6a60
·
verified ·
1 Parent(s): 61fb26c

Update file_browser_manager.py

Browse files
Files changed (1) hide show
  1. file_browser_manager.py +17 -16
file_browser_manager.py CHANGED
@@ -52,29 +52,30 @@ class FileBrowserManager:
52
  def scan_all_files(self) -> List[Dict]:
53
  """
54
  Scan all monitored directories and return file information.
55
-
56
  Returns:
57
  List of file info dicts with path, size, type, etc.
58
  """
59
- all_files = []
60
- unique_files = set()
61
-
62
  for base_dir in self.base_dirs:
63
  if not os.path.exists(base_dir):
64
  continue
65
-
66
  try:
67
  for root, dirs, files in os.walk(base_dir):
68
  for filename in files:
69
  # Skip hidden files and system files
70
  if filename.startswith('.') or filename.endswith('.json'):
71
  continue
72
-
73
  filepath = os.path.join(root, filename)
74
-
75
  try:
76
  stat = os.stat(filepath)
77
 
 
78
  file_info = {
79
  'filename': filename,
80
  'path': filepath,
@@ -88,21 +89,21 @@ class FileBrowserManager:
88
  'type': self._get_file_type(filename),
89
  'base_dir': base_dir
90
  }
91
-
92
- if file_path not in unique_files:
93
- unique_files.add(file_path)
94
- all_files.append({"name": filename, "path": file_path})
95
-
 
96
  except Exception as e:
97
  log.warning(f"Failed to stat {filepath}: {e}")
98
-
99
-
100
  except Exception as e:
101
  log.error(f"Failed to scan {base_dir}: {e}")
102
-
103
  # Sort by modified time (newest first)
104
  all_files.sort(key=lambda x: x['modified'], reverse=True)
105
-
106
  return all_files
107
 
108
  def _get_file_type(self, filename: str) -> str:
 
52
  def scan_all_files(self) -> List[Dict]:
53
  """
54
  Scan all monitored directories and return file information.
55
+
56
  Returns:
57
  List of file info dicts with path, size, type, etc.
58
  """
59
+ all_files = [] # List to hold file information
60
+ unique_files = set() # Set to track unique file paths
61
+
62
  for base_dir in self.base_dirs:
63
  if not os.path.exists(base_dir):
64
  continue
65
+
66
  try:
67
  for root, dirs, files in os.walk(base_dir):
68
  for filename in files:
69
  # Skip hidden files and system files
70
  if filename.startswith('.') or filename.endswith('.json'):
71
  continue
72
+
73
  filepath = os.path.join(root, filename)
74
+
75
  try:
76
  stat = os.stat(filepath)
77
 
78
+ # Prepare file information
79
  file_info = {
80
  'filename': filename,
81
  'path': filepath,
 
89
  'type': self._get_file_type(filename),
90
  'base_dir': base_dir
91
  }
92
+
93
+ # Check for duplicates using the correct variable
94
+ if filepath not in unique_files:
95
+ unique_files.add(filepath)
96
+ all_files.append(file_info) # Append the full file_info dict
97
+
98
  except Exception as e:
99
  log.warning(f"Failed to stat {filepath}: {e}")
100
+
 
101
  except Exception as e:
102
  log.error(f"Failed to scan {base_dir}: {e}")
103
+
104
  # Sort by modified time (newest first)
105
  all_files.sort(key=lambda x: x['modified'], reverse=True)
106
+
107
  return all_files
108
 
109
  def _get_file_type(self, filename: str) -> str: