Skip to content

Commit 04ace17

Browse files
committed
Tighten pg_restore's recognition of its -F (format) option values.
Instead of checking just the first letter, match the whole string using pg_strcasecmp. Per the documentation, we allow either just the first letter (e.g. "c") or the whole name ("custom"); but we will no longer accept random variations such as "chump". This matches pg_dump's longstanding parsing code for the same option. Also for consistency with pg_dump, recognize "p"/"plain". We don't support it, but we can give a more helpful error message than "unrecognized archive format". Author: Srinath Reddy <srinath2133@gmail.com> Discussion: https://postgr.es/m/CAFC+b6pfK-BGcWW1kQmtxVrCh-JGjB2X02rLPQs_ZFaDGjZDsQ@mail.gmail.com
1 parent d2ca16b commit 04ace17

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/bin/pg_dump/pg_restore.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -383,27 +383,25 @@ main(int argc, char **argv)
383383

384384
if (opts->formatName)
385385
{
386-
switch (opts->formatName[0])
386+
if (pg_strcasecmp(opts->formatName, "c") == 0 ||
387+
pg_strcasecmp(opts->formatName, "custom") == 0)
388+
opts->format = archCustom;
389+
else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
390+
pg_strcasecmp(opts->formatName, "directory") == 0)
391+
opts->format = archDirectory;
392+
else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
393+
pg_strcasecmp(opts->formatName, "tar") == 0)
394+
opts->format = archTar;
395+
else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
396+
pg_strcasecmp(opts->formatName, "plain") == 0)
387397
{
388-
case 'c':
389-
case 'C':
390-
opts->format = archCustom;
391-
break;
392-
393-
case 'd':
394-
case 'D':
395-
opts->format = archDirectory;
396-
break;
397-
398-
case 't':
399-
case 'T':
400-
opts->format = archTar;
401-
break;
402-
403-
default:
404-
pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
405-
opts->formatName);
398+
/* recognize this for consistency with pg_dump */
399+
pg_fatal("archive format \"%s\" is not supported; please use psql",
400+
opts->formatName);
406401
}
402+
else
403+
pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
404+
opts->formatName);
407405
}
408406

409407
AH = OpenArchive(inputFileSpec, opts->format);

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