15
15
#include "pg_upgrade.h"
16
16
17
17
static void check_data_dir (ClusterInfo * cluster );
18
- static void check_bin_dir (ClusterInfo * cluster );
18
+ static void check_bin_dir (ClusterInfo * cluster , bool check_versions );
19
19
static void get_bin_version (ClusterInfo * cluster );
20
- static void check_exec (const char * dir , const char * program );
20
+ static void check_exec (const char * dir , const char * program , bool check_version );
21
21
22
22
#ifdef WIN32
23
23
static int win32_check_directory_write_permissions (void );
@@ -257,9 +257,9 @@ verify_directories(void)
257
257
#endif
258
258
pg_fatal ("You must have read and write access in the current directory.\n" );
259
259
260
- check_bin_dir (& old_cluster );
260
+ check_bin_dir (& old_cluster , false );
261
261
check_data_dir (& old_cluster );
262
- check_bin_dir (& new_cluster );
262
+ check_bin_dir (& new_cluster , true );
263
263
check_data_dir (& new_cluster );
264
264
}
265
265
@@ -362,9 +362,13 @@ check_data_dir(ClusterInfo *cluster)
362
362
* in the binaries directory. If we find that a required executable
363
363
* is missing (or secured against us), we display an error message and
364
364
* exit().
365
+ *
366
+ * If check_versions is true, then the versions of the binaries are checked
367
+ * against the version of this pg_upgrade. This is for checking the target
368
+ * bindir.
365
369
*/
366
370
static void
367
- check_bin_dir (ClusterInfo * cluster )
371
+ check_bin_dir (ClusterInfo * cluster , bool check_versions )
368
372
{
369
373
struct stat statBuf ;
370
374
@@ -376,9 +380,9 @@ check_bin_dir(ClusterInfo *cluster)
376
380
report_status (PG_FATAL , "\"%s\" is not a directory\n" ,
377
381
cluster -> bindir );
378
382
379
- check_exec (cluster -> bindir , "postgres" );
380
- check_exec (cluster -> bindir , "pg_controldata" );
381
- check_exec (cluster -> bindir , "pg_ctl" );
383
+ check_exec (cluster -> bindir , "postgres" , check_versions );
384
+ check_exec (cluster -> bindir , "pg_controldata" , check_versions );
385
+ check_exec (cluster -> bindir , "pg_ctl" , check_versions );
382
386
383
387
/*
384
388
* Fetch the binary version after checking for the existence of pg_ctl.
@@ -389,9 +393,9 @@ check_bin_dir(ClusterInfo *cluster)
389
393
390
394
/* pg_resetxlog has been renamed to pg_resetwal in version 10 */
391
395
if (GET_MAJOR_VERSION (cluster -> bin_version ) <= 906 )
392
- check_exec (cluster -> bindir , "pg_resetxlog" );
396
+ check_exec (cluster -> bindir , "pg_resetxlog" , check_versions );
393
397
else
394
- check_exec (cluster -> bindir , "pg_resetwal" );
398
+ check_exec (cluster -> bindir , "pg_resetwal" , check_versions );
395
399
396
400
if (cluster == & new_cluster )
397
401
{
@@ -400,17 +404,17 @@ check_bin_dir(ClusterInfo *cluster)
400
404
* pg_dumpall are used to dump the old cluster, but must be of the
401
405
* target version.
402
406
*/
403
- check_exec (cluster -> bindir , "initdb" );
404
- check_exec (cluster -> bindir , "pg_dump" );
405
- check_exec (cluster -> bindir , "pg_dumpall" );
406
- check_exec (cluster -> bindir , "pg_restore" );
407
- check_exec (cluster -> bindir , "psql" );
408
- check_exec (cluster -> bindir , "vacuumdb" );
407
+ check_exec (cluster -> bindir , "initdb" , check_versions );
408
+ check_exec (cluster -> bindir , "pg_dump" , check_versions );
409
+ check_exec (cluster -> bindir , "pg_dumpall" , check_versions );
410
+ check_exec (cluster -> bindir , "pg_restore" , check_versions );
411
+ check_exec (cluster -> bindir , "psql" , check_versions );
412
+ check_exec (cluster -> bindir , "vacuumdb" , check_versions );
409
413
}
410
414
}
411
415
412
416
static void
413
- check_exec (const char * dir , const char * program )
417
+ check_exec (const char * dir , const char * program , bool check_version )
414
418
{
415
419
char path [MAXPGPATH ];
416
420
char line [MAXPGPATH ];
@@ -435,11 +439,14 @@ check_exec(const char *dir, const char *program)
435
439
pg_fatal ("check for \"%s\" failed: cannot execute\n" ,
436
440
path );
437
441
438
- pg_strip_crlf (line );
442
+ if (check_version )
443
+ {
444
+ pg_strip_crlf (line );
439
445
440
- snprintf (versionstr , sizeof (versionstr ), "%s (PostgreSQL) " PG_VERSION , program );
446
+ snprintf (versionstr , sizeof (versionstr ), "%s (PostgreSQL) " PG_VERSION , program );
441
447
442
- if (strcmp (line , versionstr ) != 0 )
443
- pg_fatal ("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"\n" ,
444
- path , line , versionstr );
448
+ if (strcmp (line , versionstr ) != 0 )
449
+ pg_fatal ("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"\n" ,
450
+ path , line , versionstr );
451
+ }
445
452
}
0 commit comments