mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
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
This commit is contained in:
@ -383,27 +383,25 @@ main(int argc, char **argv)
|
||||
|
||||
if (opts->formatName)
|
||||
{
|
||||
switch (opts->formatName[0])
|
||||
{
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (pg_strcasecmp(opts->formatName, "c") == 0 ||
|
||||
pg_strcasecmp(opts->formatName, "custom") == 0)
|
||||
opts->format = archCustom;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'D':
|
||||
else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
|
||||
pg_strcasecmp(opts->formatName, "directory") == 0)
|
||||
opts->format = archDirectory;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
case 'T':
|
||||
else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
|
||||
pg_strcasecmp(opts->formatName, "tar") == 0)
|
||||
opts->format = archTar;
|
||||
break;
|
||||
|
||||
default:
|
||||
pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
|
||||
else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
|
||||
pg_strcasecmp(opts->formatName, "plain") == 0)
|
||||
{
|
||||
/* 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);
|
||||
|
Reference in New Issue
Block a user