-
Notifications
You must be signed in to change notification settings - Fork 0
feat: use junction instead of symlink for Windows #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
804523d
feat: use junction instead of symlink for Windows
ldkv 11eaa4e
WIP: Update src/uvlink/path_utils.py
c0rychu fca904a
WIP: Update src/uvlink/path_utils.py
c0rychu 637bc79
WIP: Update src/uvlink/path_utils.py
c0rychu 70814de
WIP: Update tests/test_project.py
c0rychu e29a3ce
WIP: Update src/uvlink/path_utils.py
c0rychu 1ad428e
WIP: Update src/uvlink/cli.py
c0rychu fbf0a4e
WIP: Update src/uvlink/cli.py
c0rychu e74531b
WIP: Apply suggestion from @c0rychu
c0rychu dd6bb6e
WIP: address cursor bugbot comments
c0rychu abb6e0f
WIP: address cursor bugbot comments
c0rychu 4b04326
WIP: use Windows path format
ldkv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def is_windows() -> bool: | ||
| return sys.platform == "win32" or os.name == "nt" | ||
|
|
||
|
|
||
| def is_link_or_junction(path: Path) -> bool: | ||
| return path.is_symlink() or path.is_junction() | ||
|
|
||
|
|
||
| def path_exists(path: Path) -> bool: | ||
| return path.exists() or is_link_or_junction(path) | ||
|
|
||
|
|
||
| def create_windows_junction(symlink: Path, target: Path) -> None: | ||
| """ | ||
| Windows junctions are similar to symlinks but specifically for directories. | ||
| Does not require admin privileges as symlink_to. | ||
| """ | ||
| if not target.is_dir(): | ||
| raise ValueError("Target must be an existing directory for Windows junction.") | ||
|
|
||
| cmd = f'mklink /J "{symlink.as_posix()}" "{target.as_posix()}"' | ||
| try: | ||
| subprocess.check_call(cmd, shell=True) | ||
| except subprocess.CalledProcessError as e: | ||
| print(f"Failed to create junction. Return code: {e.returncode}") | ||
c0rychu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
c0rychu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def create_symlink(symlink: Path, target: Path) -> None: | ||
| target.mkdir(parents=True, exist_ok=True) | ||
| try: | ||
| symlink.symlink_to(target, target_is_directory=target.is_dir()) | ||
| except OSError: | ||
| if is_windows(): | ||
| create_windows_junction(symlink, target) | ||
| else: | ||
| raise | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.