Commit
·
262b475
1
Parent(s):
b088225
Update path_config.py
Browse files- path_config.py +26 -4
path_config.py
CHANGED
|
@@ -79,18 +79,40 @@ class EnvironmentPathManager:
|
|
| 79 |
}
|
| 80 |
|
| 81 |
def _ensure_directories(self):
|
| 82 |
-
"""Ensure all necessary directories exist"""
|
| 83 |
for path_name, path in self.base_paths.items():
|
| 84 |
try:
|
| 85 |
path.mkdir(parents=True, exist_ok=True)
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except PermissionError:
|
| 88 |
logger.warning(f"Cannot create directory {path}, using fallback")
|
| 89 |
if path_name in ['cache', 'temp']:
|
| 90 |
# Fallback to user's home directory for cache/temp
|
| 91 |
fallback_path = Path.home() / f'.fake_news_detector/{path_name}'
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
except Exception as e:
|
| 95 |
logger.error(f"Failed to create directory {path}: {e}")
|
| 96 |
|
|
|
|
| 79 |
}
|
| 80 |
|
| 81 |
def _ensure_directories(self):
|
| 82 |
+
"""Ensure all necessary directories exist with proper error handling"""
|
| 83 |
for path_name, path in self.base_paths.items():
|
| 84 |
try:
|
| 85 |
path.mkdir(parents=True, exist_ok=True)
|
| 86 |
+
|
| 87 |
+
# Test write access
|
| 88 |
+
test_file = path / '.write_test'
|
| 89 |
+
try:
|
| 90 |
+
test_file.touch()
|
| 91 |
+
test_file.unlink()
|
| 92 |
+
logger.debug(f"Ensured directory exists with write access: {path}")
|
| 93 |
+
except (PermissionError, OSError):
|
| 94 |
+
logger.warning(f"Directory exists but no write access: {path}")
|
| 95 |
+
|
| 96 |
except PermissionError:
|
| 97 |
logger.warning(f"Cannot create directory {path}, using fallback")
|
| 98 |
if path_name in ['cache', 'temp']:
|
| 99 |
# Fallback to user's home directory for cache/temp
|
| 100 |
fallback_path = Path.home() / f'.fake_news_detector/{path_name}'
|
| 101 |
+
try:
|
| 102 |
+
fallback_path.mkdir(parents=True, exist_ok=True)
|
| 103 |
+
self.base_paths[path_name] = fallback_path
|
| 104 |
+
logger.info(f"Using fallback directory: {fallback_path}")
|
| 105 |
+
except Exception as e:
|
| 106 |
+
logger.error(f"Fallback directory creation failed: {e}")
|
| 107 |
+
elif path_name == 'logs':
|
| 108 |
+
# For logs, try using a temporary directory
|
| 109 |
+
try:
|
| 110 |
+
import tempfile
|
| 111 |
+
temp_logs = Path(tempfile.mkdtemp(prefix='logs_'))
|
| 112 |
+
self.base_paths[path_name] = temp_logs
|
| 113 |
+
logger.info(f"Using temporary logs directory: {temp_logs}")
|
| 114 |
+
except Exception as e:
|
| 115 |
+
logger.error(f"Cannot create temporary logs directory: {e}")
|
| 116 |
except Exception as e:
|
| 117 |
logger.error(f"Failed to create directory {path}: {e}")
|
| 118 |
|