Skip to content

Commit 772a5f1

Browse files
committed
Improve pg_upgrade error reporting if the bin or data directories do not
exist or are not directories.
1 parent 4a6a5c8 commit 772a5f1

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

contrib/pg_upgrade/exec.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ is_server_running(const char *datadir)
7171
if ((fd = open(path, O_RDONLY, 0)) < 0)
7272
{
7373
if (errno != ENOENT)
74-
pg_log(PG_FATAL, "could not open file \"%s\" for reading\n",
74+
/* issue a warning but continue so we can throw a clearer error later */
75+
pg_log(PG_WARNING, "could not open file \"%s\" for reading\n",
7576
path);
7677

7778
return false;
@@ -94,6 +95,8 @@ void
9495
verify_directories(void)
9596
{
9697

98+
prep_status("Checking current, bin, and data directories");
99+
97100
if (access(".", R_OK | W_OK
98101
#ifndef WIN32
99102
/*
@@ -107,20 +110,10 @@ verify_directories(void)
107110
pg_log(PG_FATAL,
108111
"You must have read and write access in the current directory.\n");
109112

110-
prep_status("Checking old data directory (%s)", old_cluster.pgdata);
111-
check_data_dir(old_cluster.pgdata);
112-
check_ok();
113-
114-
prep_status("Checking old bin directory (%s)", old_cluster.bindir);
115113
check_bin_dir(&old_cluster);
116-
check_ok();
117-
118-
prep_status("Checking new data directory (%s)", new_cluster.pgdata);
119-
check_data_dir(new_cluster.pgdata);
120-
check_ok();
121-
122-
prep_status("Checking new bin directory (%s)", new_cluster.bindir);
114+
check_data_dir(old_cluster.pgdata);
123115
check_bin_dir(&new_cluster);
116+
check_data_dir(new_cluster.pgdata);
124117
check_ok();
125118
}
126119

@@ -139,25 +132,25 @@ check_data_dir(const char *pg_data)
139132
{
140133
char subDirName[MAXPGPATH];
141134
int subdirnum;
142-
const char *requiredSubdirs[] = {"base", "global", "pg_clog",
135+
/* start check with top-most directory */
136+
const char *requiredSubdirs[] = {"", "base", "global", "pg_clog",
143137
"pg_multixact", "pg_subtrans", "pg_tblspc", "pg_twophase",
144-
"pg_xlog"};
138+
"pg_xlog"};
145139

146140
for (subdirnum = 0;
147141
subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]);
148142
++subdirnum)
149143
{
150144
struct stat statBuf;
151-
152145
snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
153146
requiredSubdirs[subdirnum]);
154147

155148
if (stat(subDirName, &statBuf) != 0)
156149
report_status(PG_FATAL, "check for %s failed: %s\n",
157-
requiredSubdirs[subdirnum], getErrorText(errno));
150+
subDirName, getErrorText(errno));
158151
else if (!S_ISDIR(statBuf.st_mode))
159152
report_status(PG_FATAL, "%s is not a directory\n",
160-
requiredSubdirs[subdirnum]);
153+
subDirName);
161154
}
162155
}
163156

@@ -173,6 +166,16 @@ check_data_dir(const char *pg_data)
173166
static void
174167
check_bin_dir(ClusterInfo *cluster)
175168
{
169+
struct stat statBuf;
170+
171+
/* check bindir */
172+
if (stat(cluster->bindir, &statBuf) != 0)
173+
report_status(PG_FATAL, "check for %s failed: %s\n",
174+
cluster->bindir, getErrorText(errno));
175+
else if (!S_ISDIR(statBuf.st_mode))
176+
report_status(PG_FATAL, "%s is not a directory\n",
177+
cluster->bindir);
178+
176179
validate_exec(cluster->bindir, "postgres");
177180
validate_exec(cluster->bindir, "pg_ctl");
178181
validate_exec(cluster->bindir, "pg_resetxlog");
@@ -211,11 +214,10 @@ validate_exec(const char *dir, const char *cmdName)
211214
*/
212215
if (stat(path, &buf) < 0)
213216
pg_log(PG_FATAL, "check for %s failed - %s\n",
214-
cmdName, getErrorText(errno));
215-
216-
if (!S_ISREG(buf.st_mode))
217+
path, getErrorText(errno));
218+
else if (!S_ISREG(buf.st_mode))
217219
pg_log(PG_FATAL, "check for %s failed - not an executable file\n",
218-
cmdName);
220+
path);
219221

220222
/*
221223
* Ensure that the file is both executable and readable (required for
@@ -227,13 +229,13 @@ validate_exec(const char *dir, const char *cmdName)
227229
if ((buf.st_mode & S_IRUSR) == 0)
228230
#endif
229231
pg_log(PG_FATAL, "check for %s failed - cannot read file (permission denied)\n",
230-
cmdName);
232+
path);
231233

232234
#ifndef WIN32
233235
if (access(path, X_OK) != 0)
234236
#else
235237
if ((buf.st_mode & S_IXUSR) == 0)
236238
#endif
237239
pg_log(PG_FATAL, "check for %s failed - cannot execute (permission denied)\n",
238-
cmdName);
240+
path);
239241
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy