h
This commit is contained in:
@@ -15,6 +15,8 @@ from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from SYS.logger import log
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
from SYS.utils import expand_path
|
||||
from SYS.database import db, get_config_all, save_config_value, rows_to_config
|
||||
|
||||
@@ -186,16 +188,16 @@ def resolve_output_dir(config: Dict[str, Any]) -> Path:
|
||||
# Verify we can access it (not a system directory with permission issues)
|
||||
if path.exists() or path.parent.exists():
|
||||
return path
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.debug("resolve_output_dir: failed to expand temp value %r: %s", temp_value, exc, exc_info=True)
|
||||
|
||||
# Then try outfile setting
|
||||
outfile_value = config.get("outfile")
|
||||
if outfile_value:
|
||||
try:
|
||||
return expand_path(outfile_value)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.debug("resolve_output_dir: failed to expand outfile value %r: %s", outfile_value, exc, exc_info=True)
|
||||
|
||||
# Fallback to system temp directory
|
||||
return Path(tempfile.gettempdir())
|
||||
@@ -313,8 +315,8 @@ def resolve_cookies_path(
|
||||
values: list[Any] = []
|
||||
try:
|
||||
values.append(config.get("cookies"))
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.debug("resolve_cookies_path: failed to read top-level cookies: %s", exc, exc_info=True)
|
||||
|
||||
try:
|
||||
tool = config.get("tool")
|
||||
@@ -323,16 +325,16 @@ def resolve_cookies_path(
|
||||
if isinstance(ytdlp, dict):
|
||||
values.append(ytdlp.get("cookies"))
|
||||
values.append(ytdlp.get("cookiefile"))
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.debug("resolve_cookies_path: failed to read tool.ytdlp cookies: %s", exc, exc_info=True)
|
||||
|
||||
try:
|
||||
ytdlp_block = config.get("ytdlp")
|
||||
if isinstance(ytdlp_block, dict):
|
||||
values.append(ytdlp_block.get("cookies"))
|
||||
values.append(ytdlp_block.get("cookiefile"))
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.debug("resolve_cookies_path: failed to read ytdlp cookies block: %s", exc, exc_info=True)
|
||||
|
||||
base_dir = script_dir or SCRIPT_DIR
|
||||
for value in values:
|
||||
@@ -488,7 +490,7 @@ def load_config() -> Dict[str, Any]:
|
||||
|
||||
# Forensics disabled: audit/mismatch/backup detection removed to simplify code.
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to build config load summary from %s", db.db_path)
|
||||
return db_config
|
||||
|
||||
_LAST_SAVED_CONFIG = {}
|
||||
@@ -518,8 +520,8 @@ def _acquire_save_lock(timeout: float = _SAVE_LOCK_TIMEOUT):
|
||||
"ts": time.time(),
|
||||
"cmdline": " ".join(sys.argv),
|
||||
}))
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to write save lock owner metadata %s: %s", lock_dir, exc)
|
||||
return lock_dir
|
||||
except FileExistsError:
|
||||
# Check for stale lock
|
||||
@@ -533,8 +535,8 @@ def _acquire_save_lock(timeout: float = _SAVE_LOCK_TIMEOUT):
|
||||
import shutil
|
||||
shutil.rmtree(lock_dir)
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to remove stale save lock dir %s", lock_dir)
|
||||
else:
|
||||
# No owner file; if directory is old enough consider it stale
|
||||
try:
|
||||
@@ -542,10 +544,10 @@ def _acquire_save_lock(timeout: float = _SAVE_LOCK_TIMEOUT):
|
||||
import shutil
|
||||
shutil.rmtree(lock_dir)
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to stat/remove stale save lock dir %s", lock_dir)
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to inspect save lock directory %s: %s", lock_dir, exc)
|
||||
if time.time() - start > timeout:
|
||||
raise ConfigSaveConflict("Save lock busy; could not acquire in time")
|
||||
time.sleep(0.1)
|
||||
@@ -558,10 +560,10 @@ def _release_save_lock(lock_dir: Path) -> None:
|
||||
if owner.exists():
|
||||
owner.unlink()
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to remove save lock owner file %s", owner)
|
||||
lock_dir.rmdir()
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to release save lock directory %s", lock_dir)
|
||||
|
||||
|
||||
def save_config(config: Dict[str, Any]) -> int:
|
||||
@@ -681,8 +683,8 @@ def save_config(config: Dict[str, Any]) -> int:
|
||||
try:
|
||||
if lock_dir is not None and lock_dir.exists():
|
||||
_release_save_lock(lock_dir)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to release save lock during save flow: %s", exc)
|
||||
|
||||
break
|
||||
except sqlite3.OperationalError as exc:
|
||||
@@ -694,8 +696,8 @@ def save_config(config: Dict[str, Any]) -> int:
|
||||
try:
|
||||
if lock_dir is not None and lock_dir.exists():
|
||||
_release_save_lock(lock_dir)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to release save lock after DB write failure: %s", exc)
|
||||
raise
|
||||
delay = _CONFIG_SAVE_RETRY_DELAY * attempts
|
||||
log(f"Database locked; retry {attempts}/{_CONFIG_SAVE_MAX_RETRIES} in {delay:.2f}s")
|
||||
@@ -705,8 +707,8 @@ def save_config(config: Dict[str, Any]) -> int:
|
||||
try:
|
||||
if lock_dir is not None and lock_dir.exists():
|
||||
_release_save_lock(lock_dir)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to release save lock after CRITICAL configuration save failure: %s", exc)
|
||||
raise
|
||||
|
||||
clear_config_cache()
|
||||
@@ -762,7 +764,8 @@ def save_config_and_verify(config: Dict[str, Any], retries: int = 3, delay: floa
|
||||
break
|
||||
elif isinstance(srv, str) and srv.strip():
|
||||
expected_key = srv.strip()
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
logger.debug("Failed to determine expected key for save verification: %s", exc, exc_info=True)
|
||||
expected_key = None
|
||||
|
||||
last_exc: Exception | None = None
|
||||
|
||||
Reference in New Issue
Block a user