Fixed misc bugs
This commit is contained in:
+26
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user