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
pull/198/head
Tom Lane 5 months ago
parent d2ca16bb50
commit 04ace176e0
  1. 36
      src/bin/pg_dump/pg_restore.c

@ -383,27 +383,25 @@ main(int argc, char **argv)
if (opts->formatName)
{
switch (opts->formatName[0])
if (pg_strcasecmp(opts->formatName, "c") == 0 ||
pg_strcasecmp(opts->formatName, "custom") == 0)
opts->format = archCustom;
else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
pg_strcasecmp(opts->formatName, "directory") == 0)
opts->format = archDirectory;
else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
pg_strcasecmp(opts->formatName, "tar") == 0)
opts->format = archTar;
else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
pg_strcasecmp(opts->formatName, "plain") == 0)
{
case 'c':
case 'C':
opts->format = archCustom;
break;
case 'd':
case 'D':
opts->format = archDirectory;
break;
case 't':
case 'T':
opts->format = archTar;
break;
default:
pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
opts->formatName);
/* recognize this for consistency with pg_dump */
pg_fatal("archive format \"%s\" is not supported; please use psql",
opts->formatName);
}
else
pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
opts->formatName);
}
AH = OpenArchive(inputFileSpec, opts->format);

Loading…
Cancel
Save