diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2025-01-25 11:24:16 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2025-01-25 11:24:16 -0500 |
commit | 04ace176e08f2c694bb66b5b91cbd9d4d0bd77ea (patch) | |
tree | d6e630fac8558855111bb98556ab583384fa75d3 | |
parent | d2ca16bb509c453eac181c1ef805ff55289df779 (diff) | |
download | postgresql-04ace176e08f2c694bb66b5b91cbd9d4d0bd77ea.tar.gz postgresql-04ace176e08f2c694bb66b5b91cbd9d4d0bd77ea.zip |
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
-rw-r--r-- | src/bin/pg_dump/pg_restore.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 88ae39d938a..c602272d7db 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/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); |