+ if (!CreateHardLink(newpath, oldpath, NULL)) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS)
+ goto error;
+ if (!DeleteFile(newpath))
+ goto error;
+ if (!CreateHardLink(newpath, oldpath, NULL))
+ goto error;
+ }
+ return 0;
+
+error:
+ set_errno_from_GetLastError();
+ return WIMLIB_ERR_LINK;
+}
+
+static int
+win32_create_symlink(const wchar_t *oldpath, const wchar_t *newpath,
+ struct apply_ctx *ctx)
+{
+ if (!(*win32func_CreateSymbolicLinkW)(newpath, oldpath, 0)) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS)
+ goto error;
+ if (!DeleteFile(newpath))
+ goto error;
+ if (!(*win32func_CreateSymbolicLinkW)(newpath, oldpath, 0))
+ goto error;
+ }