void CreateLink()

in dotnet/tools/symlink/main.c [25:63]


void CreateLink(const char *target, const char *toCreate)
{
    BOOL result;
    DWORD error;
    DWORD flag;

    if (!PathFileExists(target))
    {
        printf("File %s does not exist\n", target);
        exit(-1);
    }

    /* Fall back to symbolic linking */
    flag = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
retry:
    result = CreateSymbolicLinkA(toCreate, target, flag);
    if (!result)
    {
        error = GetLastError();
        if (error == 87 && flag != 0)
        {
            printf("SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE seems not supported\n");
            flag = 0;
            goto retry;
        }
        if (error != ERROR_ALREADY_EXISTS)
        {
            /* For uknown to me reasons, sometimes the link function failes even if long paths are enabled. */
            if (error == ERROR_PATH_NOT_FOUND && PathFileExistsA(target))
            {
                /*printf("Target file %s does exists. Ignoring error. \n", target);*/
                return;
            }
            printf("Error %d on linking %s to %s\n", error, toCreate, target);

            exit(-1);
        }
    }
}