mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Better backward compatibility in symlink creation
The new flag may result in ERROR_INVALID_PARAMETER in old Windows.
This commit is contained in:
parent
80f4746c68
commit
e7d93f7f42
1 changed files with 14 additions and 4 deletions
|
|
@ -1559,15 +1559,25 @@ int windows_symlink(const char* existing, const char* file)
|
|||
{
|
||||
wchar_t conv_buf_file[CONV_MAX];
|
||||
wchar_t conv_buf_existing[CONV_MAX];
|
||||
DWORD flags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
|
||||
|
||||
/* We must convert to the extended-length \\?\ format if the path is too long */
|
||||
/* otherwise the link creation fails. */
|
||||
/* But we don't want to always convert it, to avoid to recreate */
|
||||
/* user symlinks different than they were before */
|
||||
if (!CreateSymbolicLinkW(convert(conv_buf_file, file), convert_if_required(conv_buf_existing, existing), flags)) {
|
||||
windows_errno(GetLastError());
|
||||
return -1;
|
||||
if (!CreateSymbolicLinkW(convert(conv_buf_file, file), convert_if_required(conv_buf_existing, existing),
|
||||
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)
|
||||
) {
|
||||
DWORD error = GetLastError();
|
||||
if (GetLastError() != ERROR_INVALID_PARAMETER) {
|
||||
windows_errno(error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* retry without the new flag SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE */
|
||||
if (!CreateSymbolicLinkW(convert(conv_buf_file, file), convert_if_required(conv_buf_existing, existing), 0)) {
|
||||
windows_errno(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue