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

Expose the "deep-copy" symlink behavior via a new winsymlinks mode #16

Merged
merged 2 commits into from
Oct 22, 2020

Conversation

dscho
Copy link
Collaborator

@dscho dscho commented Oct 21, 2020

In https://gitter.im/msys2/msys2?at=5f8fe84abbffc02b582d6915, @Alexpux lamented that tar does not extract symbolic links but makes deep copies instead.

The reason for this is that we specifically override Cygwin's symlink() behavior to make deep copies instead of creating a special-crafted system file that Cygwin (MSYS2, and only those two) will recognize as symbolic link.

The patch to override this behavior is incomplete, though: it hacks up the WSYM_sysfile code path, which causes all kinds of problems:

  • Contrary to the documentation, MSYS=winsymlinks:native won't fall back to creating Cygwin-style symbolic links. Instead, it (quite surprisingly) creates deep copies instead.
  • There is no way to opt into the original Cygwin behavior because that code path is now dead code.
  • The fact that the WSYM_sysfile code path is modified to do something very different from what it is intended to do means that all changes that Cygwin makes to that code path have to be inspected, and occasionally even more hacks have to be put on top, such as 44bb133, where we specifically had to disable Cygwin's code to try creating WSL symlinks before falling back to creating system files instead).

Let's fix this by introducing a proper new mode: MSYS=winsymlinks:deepcopy. This mode is made the default so that users should be unaffected by this PR.

Users wishing to let the MSYS2 runtime create Cygwin-style symbolic links can ask for that by setting MSYS=winsymlinks:sysfile.

By fixing this issue, we can now stop disabling Cygwin's WSL symlink behavior, too: it is in the sysfile code path and won't affect the default behavior of the MSYS2 runtime.

While at it, the indentation of the original patch is fixed, too.

dscho added 2 commits October 21, 2020 13:12
…/folders.

The original patch to change the symbolic link behavior to create deep
copies instead did so in a bit of a hacky way: it used the
`WSYM_sysfile` code path, not introducing a separate mode. This makes it
impossible for users to ask for Cygwin's behavior (and it also poses a
maintenance burden: for example, we had to specifically disable Cygwin's
code to prefer to create WSL-style symlinks whenever possible instead of
using the original Cygwin hack to use special-formed system files).

Proposed new commit message when rebasing the MSYS2 patches on top of
the next Cygwin runtime version:

Instead of creating Cygwin symlinks, use deep copy by default

The new `winsymlinks` mode `deepcopy` (which is made the default) lets
calls to `symlink()` create (deep) copies of the source file/directory.

This is necessary because unlike Cygwin, MSYS2 does not try to be its
own little ecosystem that lives its life separate from regular Win32
programs: the latter have _no idea_ about Cygwin-emulated symbolic links
(i.e. system files whose contents start with `!<symlink>\xff\xfe` and
the remainder consists of the NUL-terminated, UTF-16LE-encoded symlink
target).

To support Cygwin-style symlinks, the new mode `sysfile` is introduced.

Co-authored-by: Johannes Schindelin <[email protected]>
Cygwin started to use WSL-style symbolic links by default.

Since MSYS2 decided to patch the `WSYM_sysfile` mode to make deep copies
instead, that logic had to be disabled specifically.

But now that we introduced a separate mode (`WSYM_deepcopy`) for that,
and use that by default, we can re-enable Cygwin's code so that users
wishing to experience Cygwin's symbolic link behavior can do so by
setting `MSYS=winsymlinks:sysfile`.

Essentially, this drops the patch "Don't create WSL symlinks for MSYS2".

Signed-off-by: Johannes Schindelin <[email protected]>
@lazka
Copy link
Member

lazka commented Oct 21, 2020

lgtm

@elieux
Copy link
Member

elieux commented Oct 21, 2020

Looks good. (I didn't build though.)

@dscho dscho merged commit f31004f into msys2:msys2-3_1_7-release Oct 22, 2020
@dscho dscho deleted the winsymlinks-deepcopy-msys2 branch October 22, 2020 08:59
dscho added a commit to dscho/MSYS2-packages that referenced this pull request Oct 22, 2020
This patch synchronizes msys2/MSYS2-packages/msys2-runtime with
msys2/msys2-runtime after merging
msys2/msys2-runtime#16.

We specifically override Cygwin's symlink() behavior to make deep copies
instead of creating a special-crafted system file that Cygwin (MSYS2,
and only those two) will recognize as symbolic link.

The patch to override this behavior is incomplete, though: it hacks up
the WSYM_sysfile code path, which causes all kinds of problems:

- Contrary to the documentation, MSYS=winsymlinks:native won't fall back
  to creating Cygwin-style symbolic links. Instead, it (quite
  surprisingly) creates deep copies instead.

- There is no way to opt into the original Cygwin behavior because that
  code path is now dead code.

- The fact that the WSYM_sysfile code path is modified to do something
  very different from what it is intended to do means that all changes
  that Cygwin makes to that code path have to be inspected, and
  occasionally even more hacks have to be put on top, such as 44bb133,
  where we specifically had to disable Cygwin's code to try creating WSL
  symlinks before falling back to creating system files instead).

Let's fix this by introducing a proper new mode:
MSYS=winsymlinks:deepcopy. This mode is made the default so
that users should be unaffected by this PR.

Users wishing to let the MSYS2 runtime create Cygwin-style
symbolic links can ask for that by setting
MSYS=winsymlinks:sysfile.

By fixing this issue, we can now stop disabling Cygwin's WSL
symlink behavior, too: it is in the sysfile code path and
won't affect the default behavior of the MSYS2 runtime.

While at it, the indentation of the original patch is fixed,
too.

Signed-off-by: Johannes Schindelin <[email protected]>
elieux pushed a commit to msys2/MSYS2-packages that referenced this pull request Oct 22, 2020
This patch synchronizes msys2/MSYS2-packages/msys2-runtime with
msys2/msys2-runtime after merging
msys2/msys2-runtime#16.

We specifically override Cygwin's symlink() behavior to make deep copies
instead of creating a special-crafted system file that Cygwin (MSYS2,
and only those two) will recognize as symbolic link.

The patch to override this behavior is incomplete, though: it hacks up
the WSYM_sysfile code path, which causes all kinds of problems:

- Contrary to the documentation, MSYS=winsymlinks:native won't fall back
  to creating Cygwin-style symbolic links. Instead, it (quite
  surprisingly) creates deep copies instead.

- There is no way to opt into the original Cygwin behavior because that
  code path is now dead code.

- The fact that the WSYM_sysfile code path is modified to do something
  very different from what it is intended to do means that all changes
  that Cygwin makes to that code path have to be inspected, and
  occasionally even more hacks have to be put on top, such as 44bb133,
  where we specifically had to disable Cygwin's code to try creating WSL
  symlinks before falling back to creating system files instead).

Let's fix this by introducing a proper new mode:
MSYS=winsymlinks:deepcopy. This mode is made the default so
that users should be unaffected by this PR.

Users wishing to let the MSYS2 runtime create Cygwin-style
symbolic links can ask for that by setting
MSYS=winsymlinks:sysfile.

By fixing this issue, we can now stop disabling Cygwin's WSL
symlink behavior, too: it is in the sysfile code path and
won't affect the default behavior of the MSYS2 runtime.

While at it, the indentation of the original patch is fixed,
too.

Signed-off-by: Johannes Schindelin <[email protected]>
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.

4 participants