Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(config): preserve nonempty config directory on startup

Rudy Celeklib04ab45f7ea8
diff --git a/app/config/config.py b/app/config/config.py
index 95452d20..f7dedea4 100644
--- a/app/config/config.py
+++ b/app/config/config.py
@@ -458,9 +458,16 @@ def _load_toml_config(config_path: str):
def load_config():
- # fix: IsADirectoryError: [Errno 21] Is a directory: '/MoneyPrinterTurbo/config.toml'
+ # Docker may create an empty directory when a missing config.toml is bind-mounted.
+ # Only remove that empty placeholder; a nonempty directory may contain user data.
if os.path.isdir(config_file):
- shutil.rmtree(config_file)
+ try:
+ os.rmdir(config_file)
+ except OSError as exc:
+ raise IsADirectoryError(
+ f"{config_file} is a directory and cannot be used as the config file; "
+ "move or rename it, then restart"
+ ) from exc
if not os.path.isfile(config_file):
example_file = f"{root_dir}/config.example.toml"
diff --git a/test/services/test_config.py b/test/services/test_config.py
index e304b87b..8b546a05 100644
--- a/test/services/test_config.py
+++ b/test/services/test_config.py
@@ -8,6 +8,7 @@ from tempfile import TemporaryDirectory
from unittest.mock import patch
import toml
+import pytest
from app.config import config
from app.models.llm_provider import LLM_PROVIDER_REGISTRY, get_llm_provider
@@ -164,6 +165,46 @@ class TestConfigPersistence:
assert str(config_path) in error_message
assert "TomlDecodeError" in error_message
+ def test_load_config_recovers_empty_config_directory(self):
+ """Docker can create an empty directory at a missing file bind-mount path."""
+ with TemporaryDirectory() as temp_dir:
+ root = Path(temp_dir)
+ config_path = root / "config.toml"
+ config_path.mkdir()
+ (root / "config.example.toml").write_text(
+ '[app]\nvideo_source = "pexels"\n', encoding="utf-8"
+ )
+
+ with (
+ patch.object(config, "root_dir", temp_dir),
+ patch.object(config, "config_file", str(config_path)),
+ ):
+ loaded_config = config.load_config()
+
+ assert loaded_config["app"]["video_source"] == "pexels"
+ assert config_path.is_file()
+
+ def test_load_config_preserves_nonempty_config_directory(self):
+ """A mistaken config.toml directory must not be recursively deleted."""
+ with TemporaryDirectory() as temp_dir:
+ root = Path(temp_dir)
+ config_path = root / "config.toml"
+ config_path.mkdir()
+ sentinel = config_path / "user-data.txt"
+ sentinel.write_text("keep this file", encoding="utf-8")
+ (root / "config.example.toml").write_text(
+ '[app]\nvideo_source = "pexels"\n', encoding="utf-8"
+ )
+
+ with (
+ patch.object(config, "root_dir", temp_dir),
+ patch.object(config, "config_file", str(config_path)),
+ ):
+ with pytest.raises(IsADirectoryError, match="config.toml"):
+ config.load_config()
+
+ assert sentinel.read_text(encoding="utf-8") == "keep this file"
+
def test_kimi_uses_current_default_model(self):
"""Kimi 未配置模型覆盖值时,应使用当前发布版本的默认模型。"""
provider = get_llm_provider("moonshot")