psql: small patch to correct filename formatting error in '\s FILE' output

Поиск
Список
Период
Сортировка
От Ian Lawrence Barwick
Тема psql: small patch to correct filename formatting error in '\s FILE' output
Дата
Msg-id CAB8KJ=hTb89+gMF84E22F37bObrkRDbiP5zEJfw5atWJX7UdLQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: psql: small patch to correct filename formatting error in '\s FILE' output  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
I've noticed a filename error in feedback messages from psql's '\s' command
when saving the command line history to a file specified by an absolute
filepath:

  psql (9.2.2)
  Type "help" for help.

  pgdevel=# \s history.txt
  Wrote history to file "./history.txt".
  pgdevel=# \s /tmp/history.txt
  Wrote history to file ".//tmp/history.txt".
  pgdevel=# \cd /tmp
  pgdevel=# \s /tmp/history.txt
  Wrote history to file "/tmp//tmp/history.txt".

The second and third '\s' commands display incorrect filepaths in the feedback
message, despite writing correctly to the specified file.

Also, if the specified file could not be written to, the error message displayed
formats the filepath differently (i.e. it does not prepend the current working
directory), which is potentially confusing, and certainly visually inconsistent:

  pgdevel=# \cd /tmp
  pgdevel=# \s foo/history.txt
  could not save history to file "foo/history.txt": No such file or directory
  pgdevel=# \! mkdir foo
  pgdevel=# \s foo/history.txt
  Wrote history to file "/tmp/foo/history.txt".


The attached patch rectifies these issues by adding a small function
'format_fname()' to psql/stringutils.c which formats the filepath
appropriately, depending on whether an absolute filepath was supplied
or psql's cwd is set.

  pgdevel_head=# \s history.txt
  Wrote history to file "./history.txt".
  pgdevel_head=# \s /tmp/history.txt
  Wrote history to file "/tmp/history.txt".
  pgdevel_head=# \cd /tmp
  pgdevel_head=# \s /tmp/history.txt
  Wrote history to file "/tmp/history.txt".

  pgdevel_head=# \cd /tmp
  pgdevel_head=# \s bar/history.txt
  could not save history to file "/tmp/bar/history.txt": No such file
or directory
  pgdevel_head=# \! mkdir bar
  pgdevel_head=# \s bar/history.txt
  Wrote history to file "/tmp/bar/history.txt".


Notes/caveats
- The function 'format_fname()' deterimines whether the supplied filepath is
  absolute by checking for the presence of a '/' as the first character. This
  strikes me as a bit hacky but I can't think of an alternative.
- As far as I can tell, Windows does not support the '\s' command, so there is
  presumably no need to worry about supporting Windows-style file paths
- As far as I can tell, this is the only psql slash command which, after saving
  data to a file, provides a feedback message containing the filename/path.



Regards

Ian Lawrence Barwick

Вложения

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

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: CF3+4 (was Re: Parallel query execution)
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]