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

Create repository has symlink left on Windows #5147

Closed
linquize opened this issue Jun 27, 2019 · 0 comments · Fixed by #5151
Closed

Create repository has symlink left on Windows #5147

linquize opened this issue Jun 27, 2019 · 0 comments · Fixed by #5151

Comments

@linquize
Copy link
Contributor

linquize commented Jun 27, 2019

Reproduction steps

  1. Windows 10 1809, enable developer mode so that symlink can be created without UAC elevation.
  2. Install git for Windows 2.22 and enable symlinks during setup. Therefore core.symlinks true
  3. Create a directory such as C:\123, this will be used as repository root.
  4. Run following code
git_repository *repo = NULL;
git_repository_init_options options = GIT_REPOSITORY_INIT_OPTIONS_INIT;
options.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE
git_repository_init_ext(&repo, "C:\\123", &options);

.git directory is created and initialized.
However, a temporary .git2_abcdef symlink is created in the working directory but not automatically deleted.

Expected behavior

symlink automatically deleted by libgit2.

Actual behavior

symlink not deleted.

Version of libgit2 (release number or SHA1)

v0.28.0-232-ge50d138

Operating system(s) tested

Windows 10 Pro 1809

Cause

In repository.c are_symlinks_supported(),

  1. Create a temp file .git2_abcdef where abcdef is random
  2. Delete that temp file
  3. Create a symlink .git2_abcdef that points to testing. However the file testing does not exist.
    If target does not exist, CreateSymbolicLinkW() will create the symlink as directory type, even do not specify SYMBOLIC_LINK_FLAG_DIRECTORY
  4. Check if .git2_abcdef is a symlink
  5. Delete .git2_abcdef using DeleteFileW(). If symlink type becomes directory, DeleteFileW() does not work. Here is the problem why the symlink is left!!!

Solutions

A. To test symlink, point to a file that exists, instead of that testing.
Create 2 temporary files, one is symlink that points to the other file. Then delete these 2 files.
B. Use RemoveDirectoryW() as fallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant