Skip to content
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

working_copy: implement symlinks on Windows with a helper function #2939

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

gulbanana
Copy link
Collaborator

@gulbanana gulbanana commented Feb 4, 2024

Fixes #2

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@gulbanana
Copy link
Collaborator Author

gulbanana commented Feb 4, 2024

Alright, we've got some test failures on windows-latest. They pass locally, but presumably the runner is not in developer mode and doesn't run as admin - Windows only supports symlinks if one of those things is true! I'll look into modifying the tests, which were previously #[cfg(unix)], so that they look for either success or a special "this Windows instance does not support this feature" error.

In order to achieve that I'll probably make the symlink function the same on both windows and unix, instead of just having the same name. That way we can get better error messages at runtime when this failure occurs on unconfigured-for-symlinks machines.

@gulbanana
Copy link
Collaborator Author

The exact requirements for symlinks appear to be:

  • winver 14972 or higher
  • Developer Mode on
  • pass flag SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (std does this)

@gulbanana gulbanana force-pushed the windows-symlinks branch 2 times, most recently from bbc712b to bbd9254 Compare February 4, 2024 11:59
@gulbanana
Copy link
Collaborator Author

The test changes were more invasive than I hoped and so I've split them into an extra commit. This has some nasty nested error handling, and probably needs a restructure, but I don't know what patterns we prefer for this sort of thing - feedback appreciated!

@ilyagr
Copy link
Collaborator

ilyagr commented Feb 4, 2024

Optionally, it would be nice to update docs/windows.md in this commit. This could also be done in a separate PR.

You could say:

Symbolic link support

jj supports symlinks on Windows under the following conditions:

  • winver 14972 or higher (Windows 10+)
  • "Developer Mode" is on

If those conditions are not satisfied, jj will (for now) crash when the working copy contains symlinks.

It might also be worth adding that, for colocated repos to work, the git option must be set. (Again, this can go in separately if it's a chore)

lib/src/file_util.rs Outdated Show resolved Hide resolved
lib/tests/test_local_working_copy.rs Show resolved Hide resolved
lib/tests/test_local_working_copy.rs Outdated Show resolved Hide resolved
lib/src/local_working_copy.rs Show resolved Hide resolved
@gulbanana gulbanana force-pushed the windows-symlinks branch 3 times, most recently from 1509ee3 to 7f06842 Compare February 7, 2024 13:08
@gulbanana
Copy link
Collaborator Author

Optionally, it would be nice to update docs/windows.md in this commit. This could also be done in a separate PR.

You could say:

Symbolic link support

jj supports symlinks on Windows under the following conditions:

  • winver 14972 or higher (Windows 10+)
  • "Developer Mode" is on

If those conditions are not satisfied, jj will (for now) crash when the working copy contains symlinks.

It might also be worth adding that, for colocated repos to work, the git option must be set. (Again, this can go in separately if it's a chore)

I've updated those docs, and addressed (I think!) the requested changes.

docs/windows.md Outdated Show resolved Hide resolved
lib/src/file_util.rs Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
lib/src/local_working_copy.rs Outdated Show resolved Hide resolved
lib/src/file_util.rs Show resolved Hide resolved
ilyagr added a commit to ilyagr/jj that referenced this pull request Feb 9, 2024
The main goal is to avoid having a symlink in our source tree. Currently, there
is no good way to work with the `jj` repo with `jj` on Windows.  Currently `jj`
just crashes with symlinks. This is being worked on, see e.g. martinvonz#2939, but it will
always depend on whether Developer Mode is enabled in Windows or whether
symlinks are materialized as text files with symlinks. Finally, MkDocs has
trouble following symlinks on Windows, so building docs wouldn't work there.

Another advantage is that, previously, we were lucky that MkDocs treats `insta`
header in `cli-reference@.md.snap` as a Markdown header and follows symlinks at
all. Now, we no longer depend on that.
ilyagr added a commit to ilyagr/jj that referenced this pull request Feb 9, 2024
The main goal is to avoid having a symlink in our source tree. Currently, there
is no good way to work with the `jj` repo with `jj` on Windows.  Currently `jj`
just crashes with symlinks. This is being worked on, see e.g. martinvonz#2939, but it will
always depend on whether Developer Mode is enabled in Windows or whether
symlinks are materialized as text files with symlinks. Finally, MkDocs has
trouble following symlinks on Windows, so building docs wouldn't work there.

Another advantage is that, previously, we were lucky that MkDocs treats `insta`
header in `cli-reference@.md.snap` as a Markdown header and follows symlinks at
all. Now, we no longer depend on that.
ilyagr added a commit that referenced this pull request Feb 12, 2024
The main goal is to avoid having a symlink in our source tree. Currently, there
is no good way to work with the `jj` repo with `jj` on Windows.  Currently `jj`
just crashes with symlinks. This is being worked on, see e.g. #2939, but it will
always depend on whether Developer Mode is enabled in Windows or whether
symlinks are materialized as text files with symlinks. Finally, MkDocs has
trouble following symlinks on Windows, so building docs wouldn't work there.

Another advantage is that, previously, we were lucky that MkDocs treats `insta`
header in `cli-reference@.md.snap` as a Markdown header and follows symlinks at
all. Now, we no longer depend on that.
@gulbanana gulbanana force-pushed the windows-symlinks branch 2 times, most recently from b18047d to 1dfff8a Compare February 14, 2024 14:55
@gulbanana
Copy link
Collaborator Author

I've modified the previous approach based on Martin's patch to create regular files on unsupported platforms. The supportness check goes from a cfg to a flag stored in the TreeState - always true on unix, true on windows if Developer Mode is enabled; turns out we can check that by looking in the registry. The symlink tests are now enabled on all platforms.

I've also addressed the other feedback, with the possible exception of the concern in #2939 (comment) - @yuja may want to weigh in.

@gulbanana gulbanana force-pushed the windows-symlinks branch 2 times, most recently from b3668be to 55e87b2 Compare February 15, 2024 14:24
@gulbanana
Copy link
Collaborator Author

I think that's everything for now.

Cargo.lock Outdated Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
lib/src/local_working_copy.rs Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
docs/windows.md Outdated Show resolved Hide resolved
docs/windows.md Outdated Show resolved Hide resolved
lib/src/local_working_copy.rs Show resolved Hide resolved
lib/src/file_util.rs Show resolved Hide resolved
@gulbanana
Copy link
Collaborator Author

Addressed feedback and rebased.

CHANGELOG.md Outdated Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
lib/src/file_util.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks.

enables symlink tests on windows, ignoring failures due to disabled developer mode,
and updates windows.md
@gulbanana gulbanana enabled auto-merge (rebase) March 5, 2024 07:12
@gulbanana gulbanana merged commit d661f59 into martinvonz:main Mar 5, 2024
16 checks passed
@gulbanana gulbanana deleted the windows-symlinks branch March 24, 2024 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for symlinks on Windows
4 participants