-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: Sys.remove, Unix.unlink now remove symlinks to directories
On Windows, calling `_wunlink` on a path may fail with `EACCES` if [1]: 1. the path specifies a read-only file; 2. the path specifies a directory. On Windows, a symbolic link to a directory is actually a directory with an associated reparse point. The consequence is that `_wunlink` will fail on them. However, POSIX `unlink(2)` specifies [2] that it will gladly unlink symlinks to directories. POSIX `unlink(2)` also forbids deletion of directories. To emulate that behaviour, we wrap the `_wunlink` call. If it fails with `EACCES`, we have to check whether the path is a directory with an associated reparse point, and that the type of the reparse point is a symbolic link. If so, we call `_wrmdir` on the path. [1]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/unlink-wunlink?view=msvc-160 [2]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html We cannot define `unlink_os` to `caml_win32_unlink` as ocamlyacc includes `caml/misc.h`. It would need the definition from `win32.c`, which isn't linked in ocamlyacc. Introduce the `caml/winsupport.h` header to hold common code between the runtime, lib-sys, and win32unix. This is also mandated by the name conflict between `ATOM` from `<windef.h>` and `caml/instruct.h`.
- Loading branch information
Showing
11 changed files
with
131 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/**************************************************************************/ | ||
/* */ | ||
/* OCaml */ | ||
/* */ | ||
/* David Allsopp, MetaStack Solutions Ltd. */ | ||
/* */ | ||
/* Copyright 2015 MetaStack Solutions Ltd. */ | ||
/* */ | ||
/* All rights reserved. This file is distributed under the terms of */ | ||
/* the GNU Lesser General Public License version 2.1, with the */ | ||
/* special exception on linking described in the file LICENSE. */ | ||
/* */ | ||
/**************************************************************************/ | ||
|
||
/* Operating system - Windows specific stuff */ | ||
|
||
#ifndef CAML_WINSUPPORT_H | ||
#define CAML_WINSUPPORT_H | ||
|
||
#if defined(_WIN32) && defined(CAML_INTERNALS) | ||
|
||
#include <windef.h> | ||
|
||
/* | ||
* This structure is defined inconsistently. mingw64 has it in ntdef.h (which | ||
* doesn't look like a primary header) and technically it's part of ntifs.h in | ||
* the WDK. Requiring the WDK is a bit extreme, so the definition is taken from | ||
* ntdef.h. Both ntdef.h and ntifs.h define REPARSE_DATA_BUFFER_HEADER_SIZE | ||
*/ | ||
#ifndef REPARSE_DATA_BUFFER_HEADER_SIZE | ||
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; | ||
#endif | ||
|
||
#endif | ||
|
||
#endif /* CAML_WINSUPPORT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters