Skip to content

Commit da75314

Browse files
committed
🐛 rename data dir error on windows
fix #28
1 parent 3bf667f commit da75314

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

nonebot_plugin_orm/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .utils import LoguruHandler, StreamToLogger, coroutine, get_subclasses
2626

2727
require("nonebot_plugin_localstore")
28-
from nonebot_plugin_localstore import get_data_dir
28+
from nonebot_plugin_localstore import get_data_dir, get_plugin_data_dir
2929

3030
__all__ = (
3131
# __init__
@@ -60,8 +60,16 @@
6060
_session_factory: sa_async.async_sessionmaker[sa_async.AsyncSession]
6161
_scoped_sessions: sa_async.async_scoped_session[sa_async.AsyncSession]
6262

63-
_data_dir = get_data_dir("nonebot_plugin_orm")
64-
if (_deprecated_data_dir := get_data_dir(None) / "nonebot-plugin-orm").exists():
63+
_data_dir = get_plugin_data_dir()
64+
if (
65+
_deprecated_data_dir := get_data_dir(None) / "nonebot-plugin-orm"
66+
).exists() and next(_deprecated_data_dir.iterdir(), None):
67+
if next(_data_dir.iterdir(), None):
68+
raise RuntimeError(
69+
"无法自动迁移数据目录, 请手动将 "
70+
f"{_deprecated_data_dir} 中的数据移动到 {_data_dir} 中."
71+
)
72+
_data_dir.rmdir()
6573
_deprecated_data_dir.rename(_data_dir)
6674

6775
_driver = get_driver()

0 commit comments

Comments
 (0)