Skip to content

Commit b1a2c24

Browse files
committed
fix(utils): improve path handling for Windows compatibility
Signed-off-by: MS
1 parent f6ec1c5 commit b1a2c24

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/anomalib/utils/path.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import re
3636
from pathlib import Path
37+
import sys
38+
import shutil
3739

3840

3941
def create_versioned_dir(root_dir: str | Path) -> Path:
@@ -101,8 +103,15 @@ def create_versioned_dir(root_dir: str | Path) -> Path:
101103
# Update the 'latest' symbolic link to point to the new version directory
102104
latest_link_path = root_dir / "latest"
103105
if latest_link_path.is_symlink() or latest_link_path.exists():
104-
latest_link_path.unlink()
105-
latest_link_path.symlink_to(new_version_dir, target_is_directory=True)
106+
if latest_link_path.is_dir() and not latest_link_path.is_symlink():
107+
shutil.rmtree(latest_link_path)
108+
else:
109+
latest_link_path.unlink()
110+
if sys.platform.startswith("win"):
111+
# On Windows, copy instead of symlink to avoid privilege issues
112+
shutil.copytree(new_version_dir, latest_link_path)
113+
else:
114+
latest_link_path.symlink_to(new_version_dir, target_is_directory=True)
106115

107116
return latest_link_path
108117

0 commit comments

Comments
 (0)