Skip to content

Commit 203258c

Browse files
committed
patch 7.4.1128
Problem: MS-Windows: delete() does not recognize junctions. Solution: Add mch_isrealdir() for MS-Windows. Update mch_is_symbolic_link(). (Ken Takata)
1 parent 021b593 commit 203258c

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

src/fileio.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7297,14 +7297,10 @@ delete_recursive(char_u *name)
72977297
/* A symbolic link to a directory itself is deleted, not the directory it
72987298
* points to. */
72997299
if (
7300-
# if defined(WIN32)
7301-
mch_isdir(name) && !mch_is_symbolic_link(name)
7302-
# else
7303-
# ifdef UNIX
7300+
# if defined(UNIX) || defined(WIN32)
73047301
mch_isrealdir(name)
7305-
# else
7302+
# else
73067303
mch_isdir(name)
7307-
# endif
73087304
# endif
73097305
)
73107306
{

src/os_win32.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,17 @@ mch_isdir(char_u *name)
31293129
return (f & FILE_ATTRIBUTE_DIRECTORY) != 0;
31303130
}
31313131

3132+
/*
3133+
* return TRUE if "name" is a directory, NOT a symlink to a directory
3134+
* return FALSE if "name" is not a directory
3135+
* return FALSE for error
3136+
*/
3137+
int
3138+
mch_isrealdir(char_u *name)
3139+
{
3140+
return mch_isdir(name) && !mch_is_symbolic_link(name);
3141+
}
3142+
31323143
/*
31333144
* Create directory "name".
31343145
* Return 0 on success, -1 on error.
@@ -3190,10 +3201,10 @@ mch_is_hard_link(char_u *fname)
31903201
}
31913202

31923203
/*
3193-
* Return TRUE if file "fname" is a symbolic link.
3204+
* Return TRUE if "name" is a symbolic link (or a junction).
31943205
*/
31953206
int
3196-
mch_is_symbolic_link(char_u *fname)
3207+
mch_is_symbolic_link(char_u *name)
31973208
{
31983209
HANDLE hFind;
31993210
int res = FALSE;
@@ -3204,7 +3215,7 @@ mch_is_symbolic_link(char_u *fname)
32043215
WIN32_FIND_DATAW findDataW;
32053216

32063217
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3207-
wn = enc_to_utf16(fname, NULL);
3218+
wn = enc_to_utf16(name, NULL);
32083219
if (wn != NULL)
32093220
{
32103221
hFind = FindFirstFileW(wn, &findDataW);
@@ -3213,7 +3224,7 @@ mch_is_symbolic_link(char_u *fname)
32133224
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
32143225
{
32153226
/* Retry with non-wide function (for Windows 98). */
3216-
hFind = FindFirstFile(fname, &findDataA);
3227+
hFind = FindFirstFile(name, &findDataA);
32173228
if (hFind != INVALID_HANDLE_VALUE)
32183229
{
32193230
fileFlags = findDataA.dwFileAttributes;
@@ -3229,7 +3240,7 @@ mch_is_symbolic_link(char_u *fname)
32293240
else
32303241
#endif
32313242
{
3232-
hFind = FindFirstFile(fname, &findDataA);
3243+
hFind = FindFirstFile(name, &findDataA);
32333244
if (hFind != INVALID_HANDLE_VALUE)
32343245
{
32353246
fileFlags = findDataA.dwFileAttributes;
@@ -3241,7 +3252,8 @@ mch_is_symbolic_link(char_u *fname)
32413252
FindClose(hFind);
32423253

32433254
if ((fileFlags & FILE_ATTRIBUTE_REPARSE_POINT)
3244-
&& reparseTag == IO_REPARSE_TAG_SYMLINK)
3255+
&& (reparseTag == IO_REPARSE_TAG_SYMLINK
3256+
|| reparseTag == IO_REPARSE_TAG_MOUNT_POINT))
32453257
res = TRUE;
32463258

32473259
return res;
@@ -5839,7 +5851,8 @@ mch_delay(
58395851

58405852

58415853
/*
5842-
* this version of remove is not scared by a readonly (backup) file
5854+
* This version of remove is not scared by a readonly (backup) file.
5855+
* This can also remove a symbolic link like Unix.
58435856
* Return 0 for success, -1 for failure.
58445857
*/
58455858
int
@@ -5850,6 +5863,13 @@ mch_remove(char_u *name)
58505863
int n;
58515864
#endif
58525865

5866+
/*
5867+
* On Windows, deleting a directory's symbolic link is done by
5868+
* RemoveDirectory(): mch_rmdir. It seems unnatural, but it is fact.
5869+
*/
5870+
if (mch_isdir(name) && mch_is_symbolic_link(name))
5871+
return mch_rmdir(name);
5872+
58535873
win32_setattrs(name, FILE_ATTRIBUTE_NORMAL);
58545874

58555875
#ifdef FEAT_MBYTE

src/proto/os_win32.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ int mch_setperm __ARGS((char_u *name, long perm));
2121
void mch_hide __ARGS((char_u *name));
2222
int mch_ishidden __ARGS((char_u *name));
2323
int mch_isdir __ARGS((char_u *name));
24+
int mch_isrealdir __ARGS((char_u *name));
2425
int mch_mkdir __ARGS((char_u *name));
2526
int mch_rmdir __ARGS((char_u *name));
2627
int mch_is_hard_link __ARGS((char_u *fname));

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1128,
744746
/**/
745747
1127,
746748
/**/

0 commit comments

Comments
 (0)