Issue18314 Allow unlink to remove junctions. Includes support for creating junctions. Patch by Kim Gräsman

This commit is contained in:
Tim Golden 2014-05-05 19:46:17 +01:00
parent a4790965f4
commit 0321cf2550
4 changed files with 235 additions and 36 deletions

View file

@ -27,6 +27,8 @@
#include "Python.h"
#ifndef MS_WINDOWS
#include "posixmodule.h"
#else
#include "winreparse.h"
#endif
#ifdef __cplusplus
@ -301,6 +303,9 @@ extern int lstat(const char *, struct stat *);
#ifndef IO_REPARSE_TAG_SYMLINK
#define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
#endif
#ifndef IO_REPARSE_TAG_MOUNT_POINT
#define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
#endif
#include "osdefs.h"
#include <malloc.h>
#include <windows.h>
@ -1109,41 +1114,6 @@ _PyVerify_fd_dup2(int fd1, int fd2)
#endif
#ifdef MS_WINDOWS
/* The following structure was copied from
http://msdn.microsoft.com/en-us/library/ms791514.aspx as the required
include doesn't seem to be present in the Windows SDK (at least as included
with Visual Studio Express). */
typedef struct _REPARSE_DATA_BUFFER {
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union {
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
ULONG Flags;
WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer;
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
} MountPointReparseBuffer;
struct {
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
#define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER,\
GenericReparseBuffer)
#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
static int
win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
@ -4492,7 +4462,10 @@ BOOL WINAPI Py_DeleteFileW(LPCWSTR lpFileName)
find_data_handle = FindFirstFileW(lpFileName, &find_data);
if(find_data_handle != INVALID_HANDLE_VALUE) {
is_link = find_data.dwReserved0 == IO_REPARSE_TAG_SYMLINK;
/* IO_REPARSE_TAG_SYMLINK if it is a symlink and
IO_REPARSE_TAG_MOUNT_POINT if it is a junction point. */
is_link = find_data.dwReserved0 == IO_REPARSE_TAG_SYMLINK ||
find_data.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT;
FindClose(find_data_handle);
}
}