Fixed misc bugs

This commit is contained in:
2025-10-15 13:31:18 +13:00
parent 9f5a25fcf5
commit 7580dc3f94
13 changed files with 609 additions and 47 deletions
+26 -4
View File
@@ -195,16 +195,38 @@ class RedditConnector(metaclass=ABCMeta):
Path(self.config_directory, "config.cfg"),
Path(self.config_directory, "default_config.cfg"),
]
logger.debug(f"Config directory is: {self.config_directory}")
logger.debug(f"Checking possible config paths: {[str(p) for p in possible_paths]}")
self.config_location = None
for path in possible_paths:
if path.resolve().expanduser().exists():
resolved_path = path.resolve().expanduser()
logger.debug(f"Checking if {resolved_path} exists: {resolved_path.exists()}")
if resolved_path.exists():
self.config_location = path
logger.debug(f"Loading configuration from {path}")
break
if not self.config_location:
with importlib.resources.path("bdfr", "default_config.cfg") as path:
self.config_location = path
shutil.copy(self.config_location, Path(self.config_directory, "default_config.cfg"))
# Try to use a fallback location that avoids importlib.resources context manager issues
# when running as non-root user in Docker
fallback_config = Path("/tmp/bdfr_default_config.cfg")
if fallback_config.exists():
logger.debug("Using fallback config from /tmp/bdfr_default_config.cfg")
shutil.copy(fallback_config, Path(self.config_directory, "default_config.cfg"))
self.config_location = Path(self.config_directory, "default_config.cfg")
else:
# Fall back to importlib.resources if no fallback is available
try:
with importlib.resources.path("bdfr", "default_config.cfg") as path:
self.config_location = path
shutil.copy(self.config_location, Path(self.config_directory, "default_config.cfg"))
except (PermissionError, OSError) as e:
logger.error(f"Failed to access default config via importlib.resources: {e}")
# Last resort: try to read from package directory directly
package_config = Path("/usr/local/lib/python3.11/site-packages/bdfr/default_config.cfg")
if package_config.exists():
logger.debug("Using package config directly")
shutil.copy(package_config, Path(self.config_directory, "default_config.cfg"))
self.config_location = Path(self.config_directory, "default_config.cfg")
if not self.config_location:
raise errors.BulkDownloaderException("Could not find a configuration file to load")
self.cfg_parser.read(self.config_location)