mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-11-28 09:33:54 +02:00
Remove custom version of readlink in pgut_port
Postgres has its own version in lpgport relying on junction points, so if we consider a WIN32 port this is actually not necessary.
This commit is contained in:
parent
1ae2feb38f
commit
fa248a0507
111
pgut/pgut-port.c
111
pgut/pgut-port.c
@ -15,117 +15,6 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <winioctl.h>
|
||||
|
||||
#define REPARSE_DATA_SIZE 1024
|
||||
|
||||
/* same layout as REPARSE_DATA_BUFFER, which is defined only in old winnt.h */
|
||||
typedef struct REPARSE_DATA
|
||||
{
|
||||
ULONG ReparseTag;
|
||||
WORD ReparseDataLength;
|
||||
WORD Reserved;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
WORD SubstituteNameOffset;
|
||||
WORD SubstituteNameLength;
|
||||
WORD PrintNameOffset;
|
||||
WORD PrintNameLength;
|
||||
ULONG Flags;
|
||||
WCHAR PathBuffer[1];
|
||||
} Symlink;
|
||||
struct
|
||||
{
|
||||
WORD SubstituteNameOffset;
|
||||
WORD SubstituteNameLength;
|
||||
WORD PrintNameOffset;
|
||||
WORD PrintNameLength;
|
||||
WCHAR PathBuffer[1];
|
||||
} Mount;
|
||||
struct
|
||||
{
|
||||
BYTE DataBuffer[REPARSE_DATA_SIZE];
|
||||
} Generic;
|
||||
};
|
||||
} REPARSE_DATA;
|
||||
|
||||
ssize_t
|
||||
readlink(const char *path, char *target, size_t size)
|
||||
{
|
||||
HANDLE handle;
|
||||
DWORD attr;
|
||||
REPARSE_DATA data;
|
||||
DWORD datasize;
|
||||
PCWSTR wpath;
|
||||
int wlen;
|
||||
int r;
|
||||
|
||||
attr = GetFileAttributes(path);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
_dosmaperr(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) == 0)
|
||||
{
|
||||
errno = EINVAL; /* not a symlink */
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle = CreateFileA(path, 0,
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
_dosmaperr(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
wpath = NULL;
|
||||
if (DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0,
|
||||
&data, sizeof(data), &datasize, NULL))
|
||||
{
|
||||
switch (data.ReparseTag)
|
||||
{
|
||||
case IO_REPARSE_TAG_MOUNT_POINT:
|
||||
{
|
||||
wpath = data.Mount.PathBuffer + data.Mount.SubstituteNameOffset;
|
||||
wlen = data.Mount.SubstituteNameLength;
|
||||
break;
|
||||
}
|
||||
case IO_REPARSE_TAG_SYMLINK:
|
||||
{
|
||||
wpath = data.Symlink.PathBuffer + data.Symlink.SubstituteNameOffset;
|
||||
wlen = data.Symlink.SubstituteNameLength;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wpath == NULL)
|
||||
r = -1;
|
||||
else
|
||||
{
|
||||
if (wcsncmp(wpath, L"\\??\\", 4) == 0 ||
|
||||
wcsncmp(wpath, L"\\\\?\\", 4) == 0)
|
||||
{
|
||||
wpath += 4;
|
||||
wlen -= 4;
|
||||
}
|
||||
r = WideCharToMultiByte(CP_ACP, 0, wpath, wlen, target, size, NULL, NULL);
|
||||
}
|
||||
|
||||
CloseHandle(handle);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PGUT_FLOCK
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -10,20 +10,6 @@
|
||||
#ifndef PGUT_PORT_H
|
||||
#define PGUT_PORT_H
|
||||
|
||||
/*
|
||||
* readlink ports
|
||||
*/
|
||||
#ifdef WIN32
|
||||
|
||||
#define S_IFLNK (0)
|
||||
#define S_IRWXG (0)
|
||||
#define S_IRWXO (0)
|
||||
#define S_ISLNK(mode) (0)
|
||||
|
||||
extern ssize_t readlink(const char *path, char *target, size_t size);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* flock ports
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user