Skip to content

Commit 7012b5e

Browse files
committed
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.
1 parent fc6d100 commit 7012b5e

File tree

5 files changed

+26
-80
lines changed

5 files changed

+26
-80
lines changed

configure

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18987,8 +18987,7 @@ fi
1898718987

1898818988

1898918989

18990-
18991-
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
18990+
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
1899218991
do
1899318992
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1899418993
{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ PGAC_VAR_INT_TIMEZONE
11931193
AC_FUNC_ACCEPT_ARGTYPES
11941194
PGAC_FUNC_GETTIMEOFDAY_1ARG
11951195

1196-
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])
1196+
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])
11971197

11981198
AC_REPLACE_FUNCS(fseeko)
11991199
case $host_os in

contrib/pg_upgrade/file.c

Lines changed: 22 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ static int copy_file(const char *fromfile, const char *tofile, bool force);
2121
static int win32_pghardlink(const char *src, const char *dst);
2222
#endif
2323

24-
#ifndef HAVE_SCANDIR
25-
static int pg_scandir_internal(const char *dirname,
26-
struct dirent *** namelist,
27-
int (*selector) (const struct dirent *));
28-
#endif
29-
3024

3125
/*
3226
* copyAndUpdateFile()
@@ -228,59 +222,18 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
228222

229223

230224
/*
231-
* pg_scandir()
232-
*
233-
* Wrapper for portable scandir functionality
234-
*/
235-
int
236-
pg_scandir(const char *dirname,
237-
struct dirent *** namelist,
238-
int (*selector) (const struct dirent *))
239-
{
240-
#ifndef HAVE_SCANDIR
241-
return pg_scandir_internal(dirname, namelist, selector);
242-
243-
/*
244-
* scandir() is originally from BSD 4.3, which had the third argument as
245-
* non-const. Linux and other C libraries have updated it to use a const.
246-
* http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg002
247-
* 14.html
248-
*
249-
* Here we try to guess which libc's need const, and which don't. The net
250-
* goal here is to try to suppress a compiler warning due to a prototype
251-
* mismatch of const usage. Ideally we would do this via autoconf, but
252-
* autoconf doesn't have a suitable builtin test and it seems overkill to
253-
* add one just to avoid a warning.
254-
*/
255-
#elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__darwin__) || defined(__OpenBSD__)
256-
/* no const */
257-
return scandir(dirname, namelist, (int (*) (struct dirent *)) selector, NULL);
258-
#else
259-
/* use const */
260-
return scandir(dirname, namelist, selector, NULL);
261-
#endif
262-
}
263-
264-
265-
#ifndef HAVE_SCANDIR
266-
/*
267-
* pg_scandir_internal()
268-
*
269-
* Implement our own scandir() on platforms that don't have it.
225+
* load_directory()
270226
*
271227
* Returns count of files that meet the selection criteria coded in
272228
* the function pointed to by selector. Creates an array of pointers
273229
* to dirent structures. Address of array returned in namelist.
274230
*
275231
* Note that the number of dirent structures needed is dynamically
276232
* allocated using realloc. Realloc can be inefficient if invoked a
277-
* large number of times. Its use in pg_upgrade is to find filesystem
278-
* filenames that have extended beyond the initial segment (file.1,
279-
* .2, etc.) and should therefore be invoked a small number of times.
233+
* large number of times.
280234
*/
281-
static int
282-
pg_scandir_internal(const char *dirname,
283-
struct dirent *** namelist, int (*selector) (const struct dirent *))
235+
int
236+
load_directory(const char *dirname, struct dirent ***namelist)
284237
{
285238
DIR *dirdesc;
286239
struct dirent *direntry;
@@ -295,42 +248,37 @@ pg_scandir_internal(const char *dirname,
295248

296249
while ((direntry = readdir(dirdesc)) != NULL)
297250
{
298-
/* Invoke the selector function to see if the direntry matches */
299-
if (!selector || (*selector) (direntry))
300-
{
301-
count++;
251+
count++;
302252

303-
*namelist = (struct dirent **) realloc((void *) (*namelist),
304-
(size_t) ((name_num + 1) * sizeof(struct dirent *)));
253+
*namelist = (struct dirent **) realloc((void *) (*namelist),
254+
(size_t) ((name_num + 1) * sizeof(struct dirent *)));
305255

306-
if (*namelist == NULL)
307-
{
308-
closedir(dirdesc);
309-
return -1;
310-
}
256+
if (*namelist == NULL)
257+
{
258+
closedir(dirdesc);
259+
return -1;
260+
}
311261

312-
entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
313-
strlen(direntry->d_name) + 1;
262+
entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
263+
strlen(direntry->d_name) + 1;
314264

315-
(*namelist)[name_num] = (struct dirent *) malloc(entrysize);
265+
(*namelist)[name_num] = (struct dirent *) malloc(entrysize);
316266

317-
if ((*namelist)[name_num] == NULL)
318-
{
319-
closedir(dirdesc);
320-
return -1;
321-
}
267+
if ((*namelist)[name_num] == NULL)
268+
{
269+
closedir(dirdesc);
270+
return -1;
271+
}
322272

323-
memcpy((*namelist)[name_num], direntry, entrysize);
273+
memcpy((*namelist)[name_num], direntry, entrysize);
324274

325-
name_num++;
326-
}
275+
name_num++;
327276
}
328277

329278
closedir(dirdesc);
330279

331280
return count;
332281
}
333-
#endif
334282

335283

336284
void

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ const char *setupPageConverter(pageCnvCtx **result);
333333
typedef void *pageCnvCtx;
334334
#endif
335335

336-
int pg_scandir(const char *dirname, struct dirent *** namelist,
337-
int (*selector) (const struct dirent *));
336+
int load_directory(const char *dirname, struct dirent ***namelist);
338337
const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
339338
const char *dst, bool force);
340339
const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src,

contrib/pg_upgrade/relfilenode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
160160
}
161161

162162
snprintf(old_dir, sizeof(old_dir), "%s", maps[mapnum].old_dir);
163-
numFiles = pg_scandir(old_dir, &namelist, NULL);
163+
numFiles = load_directory(old_dir, &namelist);
164164
}
165165

166166
/* Copying files might take some time, so give feedback. */

0 commit comments

Comments
 (0)