From 9e3fa692197d71f93a6d15e785962b3ac9c547af Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Tue, 20 Oct 2026 14:39:48 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20#=20=E4=BF=AE=E5=A4=8D=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integrations/zhenxun/data_paths.py | 2 +- tests/test_data_directory.py | 27 +++++++++++++++++++++++++++ tests/test_zhenxun_runtime.py | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/integrations/zhenxun/data_paths.py b/integrations/zhenxun/data_paths.py index 8da924c..b747176 100644 --- a/integrations/zhenxun/data_paths.py +++ b/integrations/zhenxun/data_paths.py @@ -14,7 +14,7 @@ def prepare_directory(target, legacy=None): if legacy is not None: legacy = Path(legacy).absolute() if (target.name != 'farm_db' or legacy.name != 'farm_preview' - or target.parent != legacy.parent): + or target.parent.resolve() != legacy.parent.resolve()): raise ValueError('Farm migration requires default sibling paths') if target.is_symlink() or legacy.is_symlink(): raise ValueError('Farm migration does not follow directory links') diff --git a/tests/test_data_directory.py b/tests/test_data_directory.py index e1b0a5e..471c5db 100644 --- a/tests/test_data_directory.py +++ b/tests/test_data_directory.py @@ -1,4 +1,5 @@ import importlib.util +import os from pathlib import Path import tempfile import unittest @@ -56,3 +57,29 @@ class DataDirectoryTests(unittest.TestCase): self.module.prepare_directory( self.base / 'farm_db', self.base / 'other/farm_preview', ) + + @unittest.skipUnless(os.name == 'nt', 'Windows short paths only') + def test_migration_accepts_short_and_long_parent_paths(self): + import ctypes + + parent = self.base / 'Farm migration long directory' + parent.mkdir() + buffer = ctypes.create_unicode_buffer(32768) + get_short_path = ctypes.windll.kernel32.GetShortPathNameW + get_short_path.argtypes = ( + ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint, + ) + get_short_path.restype = ctypes.c_uint + length = get_short_path(str(parent), buffer, len(buffer)) + self.assertTrue(0 < length < len(buffer)) + short_parent = Path(buffer.value) + if short_parent == parent.resolve(): + self.skipTest('Short path aliases are disabled on this volume') + old = short_parent / 'farm_preview' + old.mkdir() + (old / 'farm-preview.sqlite3').write_bytes(b'preserved') + target = parent.resolve() / 'farm_db' + self.assertTrue(self.module.prepare_directory(target, old)) + self.assertEqual((target / 'farm-preview.sqlite3').read_bytes(), + b'preserved') + self.assertFalse(old.exists()) diff --git a/tests/test_zhenxun_runtime.py b/tests/test_zhenxun_runtime.py index 9472ce7..52c950f 100644 --- a/tests/test_zhenxun_runtime.py +++ b/tests/test_zhenxun_runtime.py @@ -288,7 +288,8 @@ class ZhenxunRuntimeTests(unittest.IsolatedAsyncioTestCase): )} with patch.dict(sys.modules, modules): imported = importlib.import_module(self.package + ".commands") - self.assertEqual(imported.runtime.data_dir, self.root / 'farm_db') + self.assertEqual(imported.runtime.data_dir, + (self.root / 'farm_db').resolve()) self.assertEqual(set(hooks["commands"]), set(self.module.COMMANDS)) self.assertEqual(len(hooks["start"]), 1) await hooks["start"][0]()