pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18245: pg_restore accepts same output file name as input file name
4+ messages / 4 participants
[nested] [flat]

* BUG #18245: pg_restore accepts same output file name as input file name
@ 2023-12-13 03:39 PG Bug reporting form <noreply@postgresql.org>
  2023-12-13 08:44 ` Re: BUG #18245: pg_restore accepts same output file name as input file name Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 4+ messages in thread

From: PG Bug reporting form @ 2023-12-13 03:39 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: mb.alzouabi@gmail.com

The following bug has been logged on the website:

Bug reference:      18245
Logged by:          Mohammad Al Zouabi
Email address:      mb.alzouabi@gmail.com
PostgreSQL version: 14.10
Operating system:   macOS
Description:        

Please let it fail when the user passes the same name for the output as the
input. 

I just lost a very important .tar file because I forgot to replace .tar with
.sql.

Thanks!



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #18245: pg_restore accepts same output file name as input file name
  2023-12-13 03:39 BUG #18245: pg_restore accepts same output file name as input file name PG Bug reporting form <noreply@postgresql.org>
@ 2023-12-13 08:44 ` Daniel Gustafsson <daniel@yesql.se>
  2023-12-14 14:38   ` Re: BUG #18245: pg_restore accepts same output file name as input file name Julien Rouhaud <rjuju123@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Daniel Gustafsson @ 2023-12-13 08:44 UTC (permalink / raw)
  To: mb.alzouabi@gmail.com; pgsql-bugs@lists.postgresql.org

> On 13 Dec 2023, at 04:39, PG Bug reporting form <noreply@postgresql.org> wrote:

> Please let it fail when the user passes the same name for the output as the
> input. 

I think this sounds like a fair restriction, input and output being the same
seems much more likely to be a copy/paste issue than an interesting usecase.
Something like the attached (untested) sketch should be enough I think.

--
Daniel Gustafsson

Attachments:

pg_restore_filecheck.diff (application/octet-stream, 725B) download diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index c3beacdec1..a032284dbc 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -315,6 +315,13 @@ main(int argc, char **argv) exit_nicely(1); } + /* Complain if the input file is used as the output file */ + if (opts->filename && inputFileSpec) + { + if (strcmp(opts->filename, "-") != 0 && strcmp(opts->filename, inputFileSpec) == 0) + pg_fatal("input file and output file cannot be the same"); + } + /* Complain if neither -f nor -d was specified (except if dumping TOC) */ if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary) pg_fatal("one of -d/--dbname and -f/--file must be specified");
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: BUG #18245: pg_restore accepts same output file name as input file name
  2023-12-13 03:39 BUG #18245: pg_restore accepts same output file name as input file name PG Bug reporting form <noreply@postgresql.org>
  2023-12-13 08:44 ` Re: BUG #18245: pg_restore accepts same output file name as input file name Daniel Gustafsson <daniel@yesql.se>
@ 2023-12-14 14:38   ` Julien Rouhaud <rjuju123@gmail.com>
  2023-12-14 14:50     ` Re: BUG #18245: pg_restore accepts same output file name as input file name Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Julien Rouhaud @ 2023-12-14 14:38 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; +Cc: mb.alzouabi@gmail.com; pgsql-bugs@lists.postgresql.org

Hi,

On Wed, Dec 13, 2023 at 09:44:26AM +0100, Daniel Gustafsson wrote:
> > On 13 Dec 2023, at 04:39, PG Bug reporting form <noreply@postgresql.org> wrote:
>
> > Please let it fail when the user passes the same name for the output as the
> > input.
>
> I think this sounds like a fair restriction, input and output being the same
> seems much more likely to be a copy/paste issue than an interesting usecase.

+1

> Something like the attached (untested) sketch should be enough I think.

I'm wondering if it would be worth adding some canonicalize_path() calls while
at it,  ISTM that such mistakes are likely to happen when invoking pg_restore
manually, so having slightly different wording for the exact same file wouldn't
surprising.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #18245: pg_restore accepts same output file name as input file name
  2023-12-13 03:39 BUG #18245: pg_restore accepts same output file name as input file name PG Bug reporting form <noreply@postgresql.org>
  2023-12-13 08:44 ` Re: BUG #18245: pg_restore accepts same output file name as input file name Daniel Gustafsson <daniel@yesql.se>
  2023-12-14 14:38   ` Re: BUG #18245: pg_restore accepts same output file name as input file name Julien Rouhaud <rjuju123@gmail.com>
@ 2023-12-14 14:50     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2023-12-14 14:50 UTC (permalink / raw)
  To: Julien Rouhaud <rjuju123@gmail.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; mb.alzouabi@gmail.com; pgsql-bugs@lists.postgresql.org

Julien Rouhaud <rjuju123@gmail.com> writes:
> On Wed, Dec 13, 2023 at 09:44:26AM +0100, Daniel Gustafsson wrote:
>> Something like the attached (untested) sketch should be enough I think.

> I'm wondering if it would be worth adding some canonicalize_path() calls while
> at it,  ISTM that such mistakes are likely to happen when invoking pg_restore
> manually, so having slightly different wording for the exact same file wouldn't
> surprising.

I'm a little dubious about the value of this; but if we're going to do
it, comparing post-canonicalize_path strings does seem like the right
way.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2023-12-14 14:50 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-12-13 03:39 BUG #18245: pg_restore accepts same output file name as input file name PG Bug reporting form <noreply@postgresql.org>
2023-12-13 08:44 ` Daniel Gustafsson <daniel@yesql.se>
2023-12-14 14:38   ` Julien Rouhaud <rjuju123@gmail.com>
2023-12-14 14:50     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox