MCPcopy
hub / github.com/MaaEnd/MaaEnd / create_directory_link

Function create_directory_link

tools/setup_workspace.py:27–56  ·  view source on GitHub ↗

在指定位置创建一个指定目录的链接 - Windows:Junction - Unix/macOS:symlink

(src: Path, dst: Path)

Source from the content-addressed store, hash-verified

25
26
27def create_directory_link(src: Path, dst: Path) -> bool:
28 """
29 在指定位置创建一个指定目录的链接
30 - Windows:Junction
31 - Unix/macOS:symlink
32 """
33 if dst.exists() or dst.is_symlink():
34 if dst.is_dir() and not dst.is_symlink():
35 try:
36 dst.rmdir()
37 except OSError:
38 shutil.rmtree(dst)
39 else:
40 dst.unlink(missing_ok=True)
41
42 dst.parent.mkdir(parents=True, exist_ok=True)
43
44 if platform.system() == "Windows":
45 result = subprocess.run(
46 ["cmd", "/c", "mklink", "/J", str(dst), str(src)],
47 capture_output=True,
48 text=True,
49 )
50 if result.returncode != 0:
51 print(Console.err(t("err_create_junction_failed", stderr=result.stderr)))
52 return False
53 else:
54 dst.symlink_to(src)
55
56 return True
57
58LOCALS_DIR = Path(__file__).parent / "locals" / "setup_workspace"
59

Callers 1

install_maafwFunction · 0.70

Calls 3

errMethod · 0.80
tFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected