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
psql-save-history-2013-01-21.patch
Description: Binary data
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers