mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Remove scandir() requirement in pg_upgrade; instead just use readdir()
--- we were not using the scandir pattern filtering anyway. This also removes the scandir requirement in configure.
This commit is contained in:
parent
fc6d1006bd
commit
7012b5edb7
3
configure
vendored
3
configure
vendored
@ -18987,8 +18987,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for ac_func in cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l
|
||||||
for ac_func in cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink scandir setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l
|
|
||||||
do
|
do
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
|
{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||||
|
@ -1193,7 +1193,7 @@ PGAC_VAR_INT_TIMEZONE
|
|||||||
AC_FUNC_ACCEPT_ARGTYPES
|
AC_FUNC_ACCEPT_ARGTYPES
|
||||||
PGAC_FUNC_GETTIMEOFDAY_1ARG
|
PGAC_FUNC_GETTIMEOFDAY_1ARG
|
||||||
|
|
||||||
AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink scandir setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l])
|
AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getifaddrs getpeerucred getrlimit memmove poll pstat readlink setproctitle setsid sigprocmask symlink sysconf towlower utime utimes waitpid wcstombs wcstombs_l])
|
||||||
|
|
||||||
AC_REPLACE_FUNCS(fseeko)
|
AC_REPLACE_FUNCS(fseeko)
|
||||||
case $host_os in
|
case $host_os in
|
||||||
|
@ -21,12 +21,6 @@ static int copy_file(const char *fromfile, const char *tofile, bool force);
|
|||||||
static int win32_pghardlink(const char *src, const char *dst);
|
static int win32_pghardlink(const char *src, const char *dst);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_SCANDIR
|
|
||||||
static int pg_scandir_internal(const char *dirname,
|
|
||||||
struct dirent *** namelist,
|
|
||||||
int (*selector) (const struct dirent *));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copyAndUpdateFile()
|
* copyAndUpdateFile()
|
||||||
@ -228,45 +222,7 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* pg_scandir()
|
* load_directory()
|
||||||
*
|
|
||||||
* Wrapper for portable scandir functionality
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
pg_scandir(const char *dirname,
|
|
||||||
struct dirent *** namelist,
|
|
||||||
int (*selector) (const struct dirent *))
|
|
||||||
{
|
|
||||||
#ifndef HAVE_SCANDIR
|
|
||||||
return pg_scandir_internal(dirname, namelist, selector);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* scandir() is originally from BSD 4.3, which had the third argument as
|
|
||||||
* non-const. Linux and other C libraries have updated it to use a const.
|
|
||||||
* http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg002
|
|
||||||
* 14.html
|
|
||||||
*
|
|
||||||
* Here we try to guess which libc's need const, and which don't. The net
|
|
||||||
* goal here is to try to suppress a compiler warning due to a prototype
|
|
||||||
* mismatch of const usage. Ideally we would do this via autoconf, but
|
|
||||||
* autoconf doesn't have a suitable builtin test and it seems overkill to
|
|
||||||
* add one just to avoid a warning.
|
|
||||||
*/
|
|
||||||
#elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__darwin__) || defined(__OpenBSD__)
|
|
||||||
/* no const */
|
|
||||||
return scandir(dirname, namelist, (int (*) (struct dirent *)) selector, NULL);
|
|
||||||
#else
|
|
||||||
/* use const */
|
|
||||||
return scandir(dirname, namelist, selector, NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_SCANDIR
|
|
||||||
/*
|
|
||||||
* pg_scandir_internal()
|
|
||||||
*
|
|
||||||
* Implement our own scandir() on platforms that don't have it.
|
|
||||||
*
|
*
|
||||||
* Returns count of files that meet the selection criteria coded in
|
* Returns count of files that meet the selection criteria coded in
|
||||||
* the function pointed to by selector. Creates an array of pointers
|
* the function pointed to by selector. Creates an array of pointers
|
||||||
@ -274,13 +230,10 @@ pg_scandir(const char *dirname,
|
|||||||
*
|
*
|
||||||
* Note that the number of dirent structures needed is dynamically
|
* Note that the number of dirent structures needed is dynamically
|
||||||
* allocated using realloc. Realloc can be inefficient if invoked a
|
* allocated using realloc. Realloc can be inefficient if invoked a
|
||||||
* large number of times. Its use in pg_upgrade is to find filesystem
|
* large number of times.
|
||||||
* filenames that have extended beyond the initial segment (file.1,
|
|
||||||
* .2, etc.) and should therefore be invoked a small number of times.
|
|
||||||
*/
|
*/
|
||||||
static int
|
int
|
||||||
pg_scandir_internal(const char *dirname,
|
load_directory(const char *dirname, struct dirent ***namelist)
|
||||||
struct dirent *** namelist, int (*selector) (const struct dirent *))
|
|
||||||
{
|
{
|
||||||
DIR *dirdesc;
|
DIR *dirdesc;
|
||||||
struct dirent *direntry;
|
struct dirent *direntry;
|
||||||
@ -295,42 +248,37 @@ pg_scandir_internal(const char *dirname,
|
|||||||
|
|
||||||
while ((direntry = readdir(dirdesc)) != NULL)
|
while ((direntry = readdir(dirdesc)) != NULL)
|
||||||
{
|
{
|
||||||
/* Invoke the selector function to see if the direntry matches */
|
count++;
|
||||||
if (!selector || (*selector) (direntry))
|
|
||||||
|
*namelist = (struct dirent **) realloc((void *) (*namelist),
|
||||||
|
(size_t) ((name_num + 1) * sizeof(struct dirent *)));
|
||||||
|
|
||||||
|
if (*namelist == NULL)
|
||||||
{
|
{
|
||||||
count++;
|
closedir(dirdesc);
|
||||||
|
return -1;
|
||||||
*namelist = (struct dirent **) realloc((void *) (*namelist),
|
|
||||||
(size_t) ((name_num + 1) * sizeof(struct dirent *)));
|
|
||||||
|
|
||||||
if (*namelist == NULL)
|
|
||||||
{
|
|
||||||
closedir(dirdesc);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
|
|
||||||
strlen(direntry->d_name) + 1;
|
|
||||||
|
|
||||||
(*namelist)[name_num] = (struct dirent *) malloc(entrysize);
|
|
||||||
|
|
||||||
if ((*namelist)[name_num] == NULL)
|
|
||||||
{
|
|
||||||
closedir(dirdesc);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy((*namelist)[name_num], direntry, entrysize);
|
|
||||||
|
|
||||||
name_num++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
|
||||||
|
strlen(direntry->d_name) + 1;
|
||||||
|
|
||||||
|
(*namelist)[name_num] = (struct dirent *) malloc(entrysize);
|
||||||
|
|
||||||
|
if ((*namelist)[name_num] == NULL)
|
||||||
|
{
|
||||||
|
closedir(dirdesc);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy((*namelist)[name_num], direntry, entrysize);
|
||||||
|
|
||||||
|
name_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dirdesc);
|
closedir(dirdesc);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -333,8 +333,7 @@ const char *setupPageConverter(pageCnvCtx **result);
|
|||||||
typedef void *pageCnvCtx;
|
typedef void *pageCnvCtx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int pg_scandir(const char *dirname, struct dirent *** namelist,
|
int load_directory(const char *dirname, struct dirent ***namelist);
|
||||||
int (*selector) (const struct dirent *));
|
|
||||||
const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
|
const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
|
||||||
const char *dst, bool force);
|
const char *dst, bool force);
|
||||||
const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
|
const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
|
||||||
|
@ -160,7 +160,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(old_dir, sizeof(old_dir), "%s", maps[mapnum].old_dir);
|
snprintf(old_dir, sizeof(old_dir), "%s", maps[mapnum].old_dir);
|
||||||
numFiles = pg_scandir(old_dir, &namelist, NULL);
|
numFiles = load_directory(old_dir, &namelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copying files might take some time, so give feedback. */
|
/* Copying files might take some time, so give feedback. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user