Re: psql -f doesn't complain about directories

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: psql -f doesn't complain about directories
Дата
Msg-id 200711271904.08992.peter_e@gmx.net
обсуждение исходный текст
Ответ на Re: psql -f doesn't complain about directories  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: psql -f doesn't complain about directories  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Am Donnerstag, 15. November 2007 schrieb Tom Lane:
> Peter Eisentraut <peter_e@gmx.net> writes:
> > Am Donnerstag, 15. November 2007 schrieb Tom Lane:
> >> This seems too far removed from the scene of the crime
> >
> > Yeah, my zeroth attempt was to place this in gets_fromFile(), but there
> > you don't have any opportunity to report failure to the main loop.  We'd
> > need to change the function signature to be able to pass that around. 
> > Maybe that's better overall.
>
> Well, you could still handle that the same as in your patch: on NULL
> return, check ferror.  It's just that I don't trust errno to stay
> unchanged for very long.

This should do better:

diff -ur ../cvs-pgsql/src/bin/psql/input.c ./src/bin/psql/input.c
--- ../cvs-pgsql/src/bin/psql/input.c   2007-01-12 10:22:42.000000000 +0100
+++ ./src/bin/psql/input.c      2007-11-27 18:46:34.000000000 +0100
@@ -179,9 +179,16 @@               /* Disable SIGINT again */               sigint_interrupt_enabled = false;

-               /* EOF? */
+               /* EOF or error? */               if (result == NULL)
+               {
+                       if (ferror(source))
+                       {
+                               psql_error("could not read from input file: %s\n", strerror(errno));
+                               return NULL;
+                       }                       break;
+               }
               appendPQExpBufferStr(buffer, line);

diff -ur ../cvs-pgsql/src/bin/psql/mainloop.c ./src/bin/psql/mainloop.c
--- ../cvs-pgsql/src/bin/psql/mainloop.c        2007-01-12 10:22:42.000000000 +0100
+++ ./src/bin/psql/mainloop.c   2007-11-27 18:30:13.000000000 +0100
@@ -129,7 +129,11 @@                       line = gets_interactive(get_prompt(prompt_status));               }
    else
 
+               {                       line = gets_fromFile(source);
+                       if (!line && ferror(source))
+                               successResult = EXIT_FAILURE;
+               }
               /*                * query_buf holds query already accumulated.  line is the malloc'd

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Sorting Improvements for 8.4
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: Quality and Performance