psql: small patch to correct filename formatting error in '\s FILE' output
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
Attachments:
psql-save-history-2013-01-21.patchapplication/octet-stream; name=psql-save-history-2013-01-21.patchDownload
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
new file mode 100644
index 740884f..d3b97ca
*** a/src/bin/psql/command.c
--- b/src/bin/psql/command.c
***************
*** 7,12 ****
--- 7,13 ----
*/
#include "postgres_fe.h"
#include "command.h"
+ #include "stringutils.h"
#ifdef __BORLANDC__ /* needed for BCC */
#undef mkdir
*************** exec_command(const char *cmd,
*** 1047,1054 ****
/* This scrolls off the screen when using /dev/tty */
success = saveHistory(fname ? fname : DEVTTY, -1, false, false);
if (success && !pset.quiet && fname)
! printf(gettext("Wrote history to file \"%s/%s\".\n"),
! pset.dirname ? pset.dirname : ".", fname);
if (!fname)
putchar('\n');
free(fname);
--- 1048,1060 ----
/* This scrolls off the screen when using /dev/tty */
success = saveHistory(fname ? fname : DEVTTY, -1, false, false);
if (success && !pset.quiet && fname)
! {
! char *fname_formatted = format_fname(fname, pset.dirname);
! printf(gettext("Wrote history to file \"%s\".\n"),
! fname_formatted);
! free(fname_formatted);
! }
!
if (!fname)
putchar('\n');
free(fname);
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
new file mode 100644
index 07c9e89..092ce93
*** a/src/bin/psql/input.c
--- b/src/bin/psql/input.c
***************
*** 16,21 ****
--- 16,22 ----
#include "settings.h"
#include "tab-complete.h"
#include "common.h"
+ #include "stringutils.h"
#ifndef WIN32
#define PSQLHISTORY ".psql_history"
*************** bool
*** 341,347 ****
saveHistory(char *fname, int max_lines, bool appendFlag, bool encodeFlag)
{
#ifdef USE_READLINE
!
/*
* Suppressing the write attempt when HISTFILE is set to /dev/null may
* look like a negligible optimization, but it's necessary on e.g. Darwin,
--- 342,348 ----
saveHistory(char *fname, int max_lines, bool appendFlag, bool encodeFlag)
{
#ifdef USE_READLINE
! char *fname_formatted;
/*
* Suppressing the write attempt when HISTFILE is set to /dev/null may
* look like a negligible optimization, but it's necessary on e.g. Darwin,
*************** saveHistory(char *fname, int max_lines,
*** 404,411 ****
return true;
}
psql_error("could not save history to file \"%s\": %s\n",
! fname, strerror(errno));
}
#else
/* only get here in \s case, so complain */
--- 405,414 ----
return true;
}
+ fname_formatted = format_fname(fname, pset.dirname);
psql_error("could not save history to file \"%s\": %s\n",
! fname_formatted, strerror(errno));
! free(fname_formatted);
}
#else
/* only get here in \s case, so complain */
diff --git a/src/bin/psql/po/cs.po b/src/bin/psql/po/cs.po
new file mode 100644
index 2b647e5..bb0d12e
*** a/src/bin/psql/po/cs.po
--- b/src/bin/psql/po/cs.po
*************** msgstr ""
*** 10,16 ****
"Project-Id-Version: postgresql 8.4\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2009-05-21 21:08+0000\n"
! "PO-Revision-Date: 2009-05-24 15:46+0200\n"
"Last-Translator: Zden��k Kotala\n"
"Language-Team: Czech \n"
"MIME-Version: 1.0\n"
--- 10,16 ----
"Project-Id-Version: postgresql 8.4\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2009-05-21 21:08+0000\n"
! "PO-Revision-Date: 2013-01-20 10:05+0900\n"
"Last-Translator: Zden��k Kotala\n"
"Language-Team: Czech \n"
"MIME-Version: 1.0\n"
*************** msgstr "Buffer dotaz�� vypr��zdn��n."
*** 100,107 ****
#: command.c:912
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Historie zaps��na do soubor: \"%s/%s\".\n"
#: command.c:950 common.c:52 common.c:66 input.c:198 mainloop.c:69
#: mainloop.c:227 print.c:61 print.c:75
--- 100,107 ----
#: command.c:912
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Historie zaps��na do soubor: \"%s\".\n"
#: command.c:950 common.c:52 common.c:66 input.c:198 mainloop.c:69
#: mainloop.c:227 print.c:61 print.c:75
diff --git a/src/bin/psql/po/de.po b/src/bin/psql/po/de.po
new file mode 100644
index 63d33df..b8b2fc7
*** a/src/bin/psql/po/de.po
--- b/src/bin/psql/po/de.po
*************** msgstr ""
*** 10,16 ****
"Project-Id-Version: PostgreSQL 9.1\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-07-27 16:54+0000\n"
! "PO-Revision-Date: 2011-07-27 23:43+0300\n"
"Last-Translator: Peter Eisentraut <peter_e@gmx.net>\n"
"Language-Team: German <peter_e@gmx.net>\n"
"Language: de\n"
--- 10,16 ----
"Project-Id-Version: PostgreSQL 9.1\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-07-27 16:54+0000\n"
! "PO-Revision-Date: 2013-01-20 10:07+0900\n"
"Last-Translator: Peter Eisentraut <peter_e@gmx.net>\n"
"Language-Team: German <peter_e@gmx.net>\n"
"Language: de\n"
*************** msgstr "Anfragepuffer wurde gel��scht."
*** 130,137 ****
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Befehlsgeschichte in Datei ��%s/%s�� geschrieben.\n"
#: command.c:1085 common.c:52 common.c:66 common.c:90 input.c:209
#: mainloop.c:72 mainloop.c:234 print.c:137 print.c:151
--- 130,137 ----
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Befehlsgeschichte in Datei ��%s�� geschrieben.\n"
#: command.c:1085 common.c:52 common.c:66 common.c:90 input.c:209
#: mainloop.c:72 mainloop.c:234 print.c:137 print.c:151
diff --git a/src/bin/psql/po/es.po b/src/bin/psql/po/es.po
new file mode 100644
index e9ec8a8..06018ad
*** a/src/bin/psql/po/es.po
--- b/src/bin/psql/po/es.po
*************** msgstr ""
*** 13,19 ****
"Project-Id-Version: psql (PostgreSQL 9.0)\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-09-01 18:03+0000\n"
! "PO-Revision-Date: 2010-09-01 17:17-0400\n"
"Last-Translator: ��lvaro Herrera <alvherre@alvh.no-ip.org>\n"
"Language-Team: PgSQL Espa��ol <pgsql-es-ayuda@postgresql.org>\n"
"MIME-Version: 1.0\n"
--- 13,19 ----
"Project-Id-Version: psql (PostgreSQL 9.0)\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-09-01 18:03+0000\n"
! "PO-Revision-Date: 2013-01-20 10:08+0900\n"
"Last-Translator: ��lvaro Herrera <alvherre@alvh.no-ip.org>\n"
"Language-Team: PgSQL Espa��ol <pgsql-es-ayuda@postgresql.org>\n"
"MIME-Version: 1.0\n"
*************** msgstr "El b��fer de consulta ha sido re
*** 105,112 ****
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Se escribi�� la historia en el archivo ��%s/%s��.\n"
#: command.c:978 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
--- 105,112 ----
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Se escribi�� la historia en el archivo ��%s��.\n"
#: command.c:978 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
diff --git a/src/bin/psql/po/fr.po b/src/bin/psql/po/fr.po
new file mode 100644
index 658c41b..f3ba8ba
*** a/src/bin/psql/po/fr.po
--- b/src/bin/psql/po/fr.po
*************** msgstr ""
*** 12,18 ****
"Project-Id-Version: PostgreSQL 8.4\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-06-13 14:55+0000\n"
! "PO-Revision-Date: 2011-06-14 21:32+0100\n"
"Last-Translator: Guillaume Lelarge <guillaume@lelarge.info>\n"
"Language-Team: French <guillaume@lelarge.info>\n"
"Language: fr\n"
--- 12,18 ----
"Project-Id-Version: PostgreSQL 8.4\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-06-13 14:55+0000\n"
! "PO-Revision-Date: 2013-01-20 10:06+0900\n"
"Last-Translator: Guillaume Lelarge <guillaume@lelarge.info>\n"
"Language-Team: French <guillaume@lelarge.info>\n"
"Language: fr\n"
*************** msgstr "Le tampon de requ�te a �t� effac
*** 137,144 ****
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Historique sauvegard� dans le fichier � %s/%s �.\n"
#: command.c:1085
#: common.c:52
--- 137,144 ----
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Historique sauvegard� dans le fichier � %s �.\n"
#: command.c:1085
#: common.c:52
diff --git a/src/bin/psql/po/ja.po b/src/bin/psql/po/ja.po
new file mode 100644
index 1df315e..30d61ec
*** a/src/bin/psql/po/ja.po
--- b/src/bin/psql/po/ja.po
*************** msgstr ""
*** 6,12 ****
"Project-Id-Version: PostgreSQL 9.1 beta2\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-06-14 22:18+0900\n"
! "PO-Revision-Date: 2011-06-16 05:26+0900\n"
"Last-Translator: HOTTA Michihide <hotta@net-newbie.com>\n"
"Language-Team: jpug-doc <jpug-doc@ml.postgresql.jp>\n"
"MIME-Version: 1.0\n"
--- 6,12 ----
"Project-Id-Version: PostgreSQL 9.1 beta2\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-06-14 22:18+0900\n"
! "PO-Revision-Date: 2013-01-20 10:07+0900\n"
"Last-Translator: HOTTA Michihide <hotta@net-newbie.com>\n"
"Language-Team: jpug-doc <jpug-doc@ml.postgresql.jp>\n"
"MIME-Version: 1.0\n"
*************** msgstr "��������������������������������
*** 122,129 ****
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "������������ \"%s/%s\" ���������������������������������������\n"
#: command.c:1085 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
--- 122,129 ----
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "������������ \"%s\" ���������������������������������������\n"
#: command.c:1085 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
diff --git a/src/bin/psql/po/pt_BR.po b/src/bin/psql/po/pt_BR.po
new file mode 100644
index 1182e77..ff8f995
*** a/src/bin/psql/po/pt_BR.po
--- b/src/bin/psql/po/pt_BR.po
*************** msgstr ""
*** 8,14 ****
"Project-Id-Version: PostgreSQL 9.0\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-09-08 23:58-0300\n"
! "PO-Revision-Date: 2005-11-02 10:30-0300\n"
"Last-Translator: Euler Taveira de Oliveira <euler@timbira.com>\n"
"Language-Team: Brazilian Portuguese <pgbr-dev@listas.postgresql.org.br>\n"
"Language: pt_BR\n"
--- 8,14 ----
"Project-Id-Version: PostgreSQL 9.0\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-09-08 23:58-0300\n"
! "PO-Revision-Date: 2013-01-20 10:06+0900\n"
"Last-Translator: Euler Taveira de Oliveira <euler@timbira.com>\n"
"Language-Team: Brazilian Portuguese <pgbr-dev@listas.postgresql.org.br>\n"
"Language: pt_BR\n"
*************** msgstr "Buffer de consulta reiniciado (l
*** 101,108 ****
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Hist��rico escrito para arquivo \"%s/%s\".\n"
#: command.c:978 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
--- 101,108 ----
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Hist��rico escrito para arquivo \"%s\".\n"
#: command.c:978 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
diff --git a/src/bin/psql/po/sv.po b/src/bin/psql/po/sv.po
new file mode 100644
index f0db905..866d830
*** a/src/bin/psql/po/sv.po
--- b/src/bin/psql/po/sv.po
*************** msgstr ""
*** 11,17 ****
"Project-Id-Version: PostgreSQL 8.4\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-07-01 15:17+0000\n"
! "PO-Revision-Date: 2010-07-02 21:48-0400\n"
"Last-Translator: Peter Eisentraut <peter_e@gmx.net>\n"
"Language-Team: Swedish <sv@li.org>\n"
"MIME-Version: 1.0\n"
--- 11,17 ----
"Project-Id-Version: PostgreSQL 8.4\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-07-01 15:17+0000\n"
! "PO-Revision-Date: 2013-01-20 10:08+0900\n"
"Last-Translator: Peter Eisentraut <peter_e@gmx.net>\n"
"Language-Team: Swedish <sv@li.org>\n"
"MIME-Version: 1.0\n"
*************** msgstr "Fr�gebufferten har blivit bortta
*** 101,108 ****
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Kommandohistorien har skrivits till \"%s/%s\".\n"
#: command.c:978 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
--- 101,108 ----
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Kommandohistorien har skrivits till \"%s\".\n"
#: command.c:978 common.c:52 common.c:66 input.c:209 mainloop.c:72
#: mainloop.c:234 print.c:137 print.c:151
diff --git a/src/bin/psql/po/tr.po b/src/bin/psql/po/tr.po
new file mode 100644
index f515915..407821e
*** a/src/bin/psql/po/tr.po
--- b/src/bin/psql/po/tr.po
*************** msgstr ""
*** 6,12 ****
"Project-Id-Version: psql-tr\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2009-06-11 05:09+0000\n"
! "PO-Revision-Date: 2009-06-11 10:57+0200\n"
"Last-Translator: Devrim G��ND��Z <devrim@gunduz.org>\n"
"Language-Team: Turkish <ceviri@postgresql.org.tr>\n"
"MIME-Version: 1.0\n"
--- 6,12 ----
"Project-Id-Version: psql-tr\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2009-06-11 05:09+0000\n"
! "PO-Revision-Date: 2013-01-20 10:08+0900\n"
"Last-Translator: Devrim G��ND��Z <devrim@gunduz.org>\n"
"Language-Team: Turkish <ceviri@postgresql.org.tr>\n"
"MIME-Version: 1.0\n"
*************** msgstr "Sorgu tamponu s��f��rlanm����."
*** 113,120 ****
#: command.c:912
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "Ge��mi��, \"%s/%s\" dosyas��na yaz��lm����.\n"
#: command.c:950
#: common.c:52
--- 113,120 ----
#: command.c:912
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "Ge��mi��, \"%s\" dosyas��na yaz��lm����.\n"
#: command.c:950
#: common.c:52
diff --git a/src/bin/psql/po/zh_CN.po b/src/bin/psql/po/zh_CN.po
new file mode 100644
index 1a0ca28..992e561
*** a/src/bin/psql/po/zh_CN.po
--- b/src/bin/psql/po/zh_CN.po
*************** msgstr ""
*** 3,9 ****
"Project-Id-Version: psql (PostgreSQL 9.0)\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-10-01 14:42+0000\n"
! "PO-Revision-Date: 2010-10-01 13:08+0800\n"
"Last-Translator: Weibin <ssmei_2000@yahoo.com>\n"
"Language-Team: Chinese (Simplified)\n"
"com>\n"
--- 3,9 ----
"Project-Id-Version: psql (PostgreSQL 9.0)\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2010-10-01 14:42+0000\n"
! "PO-Revision-Date: 2013-01-20 10:07+0900\n"
"Last-Translator: Weibin <ssmei_2000@yahoo.com>\n"
"Language-Team: Chinese (Simplified)\n"
"com>\n"
*************** msgstr "���������������������(������)���
*** 123,130 ****
# command.c:646
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "��������������������� \"%s/%s\".\n"
# command.c:681
# common.c:85
--- 123,130 ----
# command.c:646
#: command.c:940
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "��������������������� \"%s\".\n"
# command.c:681
# common.c:85
diff --git a/src/bin/psql/po/zh_TW.po b/src/bin/psql/po/zh_TW.po
new file mode 100644
index d313637..7d4b0bb
*** a/src/bin/psql/po/zh_TW.po
--- b/src/bin/psql/po/zh_TW.po
*************** msgstr ""
*** 8,14 ****
"Project-Id-Version: PostgreSQL 9.1\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-05-16 04:41+0000\n"
! "PO-Revision-Date: 2011-05-16 15:22+0800\n"
"Last-Translator: Zhenbang Wei <znbang@gmail.com>\n"
"Language-Team: The PostgreSQL Global Development Group <Kuo.ChaoYi@gmail.com>\n"
"Language: \n"
--- 8,14 ----
"Project-Id-Version: PostgreSQL 9.1\n"
"Report-Msgid-Bugs-To: pgsql-bugs@postgresql.org\n"
"POT-Creation-Date: 2011-05-16 04:41+0000\n"
! "PO-Revision-Date: 2013-01-20 10:06+0900\n"
"Last-Translator: Zhenbang Wei <znbang@gmail.com>\n"
"Language-Team: The PostgreSQL Global Development Group <Kuo.ChaoYi@gmail.com>\n"
"Language: \n"
*************** msgstr "���������������������(������)���
*** 163,170 ****
# command.c:646
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s/%s\".\n"
! msgstr "��������������������� \"%s/%s\".\n"
# command.c:681
# common.c:85
--- 163,170 ----
# command.c:646
#: command.c:1047
#, c-format
! msgid "Wrote history to file \"%s\".\n"
! msgstr "��������������������� \"%s\".\n"
# command.c:681
# common.c:85
diff --git a/src/bin/psql/stringutils.c b/src/bin/psql/stringutils.c
new file mode 100644
index 450240d..5ce661b
*** a/src/bin/psql/stringutils.c
--- b/src/bin/psql/stringutils.c
*************** quote_if_needed(const char *source, cons
*** 341,343 ****
--- 341,375 ----
return ret;
}
+
+
+ /*
+ * format_fname
+ *
+ * Format a user-supplied filepath, either as an absolute filepath
+ * if supplied as such or psql's current working directory is set,
+ * otherwise as a relative filepath.
+ *
+ * dirname - psql's current working directory, or NULL
+ * fname - filepath supplied by user
+ */
+
+ char *
+ format_fname(const char *fname, const char *dirname) {
+ int fname_size;
+ char *fname_formatted;
+
+ Assert(fname != NULL);
+
+ fname_size = (dirname ? strlen(dirname) : 0) + strlen(fname) + 3;
+ fname_formatted = pg_malloc(fname_size);
+
+ if(!pg_strncasecmp(fname, "/", 1))
+ strncpy(fname_formatted, fname, strlen(fname) + 1);
+ else
+ sprintf(fname_formatted,"%s/%s",
+ dirname ? dirname : ".",
+ fname);
+
+ return fname_formatted;
+ }
diff --git a/src/bin/psql/stringutils.h b/src/bin/psql/stringutils.h
new file mode 100644
index b991376..2cbb180
*** a/src/bin/psql/stringutils.h
--- b/src/bin/psql/stringutils.h
*************** extern char *strtokx(const char *s,
*** 22,25 ****
--- 22,27 ----
extern char *quote_if_needed(const char *source, const char *entails_quote,
char quote, char escape, int encoding);
+ extern char *format_fname(const char *fname, const char *dirname);
+
#endif /* STRINGUTILS_H */
Ian Lawrence Barwick <barwick@gmail.com> writes:
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.
I wonder why we don't just revert commit 0725065b --- this complaint
shows that it was quite poorly thought out, and I don't really see the
need for it anyway. Aside from the complained-of bug, the code added to
the \cd command is entirely incapable of tracking through multiple \cd
operations properly.
If we did think that this specific backslash command needed to be able
to print something other than the filename as-entered, I'd be inclined
to just apply make_absolute_path() to the name, instead of relying on
inadequate dead-reckoning. However, that would require making
make_absolute_path available in src/port/ or someplace, which seems
a bit more than this "feature" is worth. Why should \s, and \s alone,
need to remind you where you're cd'd to?
Thoughts?
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
2013/1/22 Tom Lane <tgl@sss.pgh.pa.us>:
Why should \s, and \s alone,
need to remind you where you're cd'd to?
Why not just get rid of that prefixed cd'd path in \s?
[]s
--
Dickson S. Guedes
mail/xmpp: guedes@guedesoft.net - skype: guediz
http://github.com/guedes - http://guedesoft.net
http://www.postgresql.org.br
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
I wrote:
If we did think that this specific backslash command needed to be able
to print something other than the filename as-entered, I'd be inclined
to just apply make_absolute_path() to the name, instead of relying on
inadequate dead-reckoning. However, that would require making
make_absolute_path available in src/port/ or someplace, which seems
a bit more than this "feature" is worth. Why should \s, and \s alone,
need to remind you where you're cd'd to?
It strikes me that a more useful "reminder" feature could be implemented
by having \cd itself print the new current directory, which it could do
with a simple call to getcwd(), thus not requiring refactoring of
make_absolute_path. Then for instance if you'd forgotten where you
were, "\cd ." would tell you.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
2013/1/23 Tom Lane <tgl@sss.pgh.pa.us>:
I wrote:
If we did think that this specific backslash command needed to be able
to print something other than the filename as-entered, I'd be inclined
to just apply make_absolute_path() to the name, instead of relying on
inadequate dead-reckoning. However, that would require making
make_absolute_path available in src/port/ or someplace, which seems
a bit more than this "feature" is worth. Why should \s, and \s alone,
need to remind you where you're cd'd to?It strikes me that a more useful "reminder" feature could be implemented
by having \cd itself print the new current directory, which it could do
with a simple call to getcwd(), thus not requiring refactoring of
make_absolute_path. Then for instance if you'd forgotten where you
were, "\cd ." would tell you.
\! pwd does the trick as well.
However personally I prefer to get some kind of feedback from an
action, so having
\cd confirm the directory would be nice. I'll submit a patch.
Related email from the archives on this subject:
/messages/by-id/37ed240d0611200645l5b70c8ddw5fb735e0d35a7b22@mail.gmail.com
Does commit 0725065b just need to be reverted, or is an additional
patch required to remove the prefixed working directory from \s output?
Ian Barwick
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Ian Lawrence Barwick <barwick@gmail.com> writes:
Related email from the archives on this subject:
/messages/by-id/37ed240d0611200645l5b70c8ddw5fb735e0d35a7b22@mail.gmail.com
I agree with the opinion stated there that \cd with no argument really
ought to do what "cd" with no argument usually does on the platform.
So if we're going to fix \cd to print the resulting current directory,
wouldn't it work to just set "dir" to "." rather than "/" for Windows?
Does commit 0725065b just need to be reverted, or is an additional
patch required to remove the prefixed working directory from \s output?
Offhand it looked like reverting the commit would be enough, but I
didn't look hard to see if there had been any subsequent related
changes. [ pokes around... ] Well, at least there are still no other
uses of pset.dirname.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Tue, Jan 22, 2013 at 07:30:59PM -0500, Tom Lane wrote:
Ian Lawrence Barwick <barwick@gmail.com> writes:
Related email from the archives on this subject:
/messages/by-id/37ed240d0611200645l5b70c8ddw5fb735e0d35a7b22@mail.gmail.comI agree with the opinion stated there that \cd with no argument really
ought to do what "cd" with no argument usually does on the platform.
So if we're going to fix \cd to print the resulting current directory,
wouldn't it work to just set "dir" to "." rather than "/" for Windows?Does commit 0725065b just need to be reverted, or is an additional
patch required to remove the prefixed working directory from \s output?Offhand it looked like reverting the commit would be enough, but I
didn't look hard to see if there had been any subsequent related
changes. [ pokes around... ] Well, at least there are still no other
uses of pset.dirname.
I still see that weird behavior in git head:
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".
Should I revert the suggested patch?
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
2013/9/10 Bruce Momjian <bruce@momjian.us>:
On Tue, Jan 22, 2013 at 07:30:59PM -0500, Tom Lane wrote:
Ian Lawrence Barwick <barwick@gmail.com> writes:
Related email from the archives on this subject:
/messages/by-id/37ed240d0611200645l5b70c8ddw5fb735e0d35a7b22@mail.gmail.comI agree with the opinion stated there that \cd with no argument really
ought to do what "cd" with no argument usually does on the platform.
So if we're going to fix \cd to print the resulting current directory,
wouldn't it work to just set "dir" to "." rather than "/" for Windows?Does commit 0725065b just need to be reverted, or is an additional
patch required to remove the prefixed working directory from \s output?Offhand it looked like reverting the commit would be enough, but I
didn't look hard to see if there had been any subsequent related
changes. [ pokes around... ] Well, at least there are still no other
uses of pset.dirname.I still see that weird behavior in git head:
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".Should I revert the suggested patch?
IIRC the patch was never applied, the reversion candidate is the existing
commit 0725065b.
(Sorry for not following up earlier, this one dropped off my radar).
Regards
Ian Barwick
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Ian Lawrence Barwick <barwick@gmail.com> writes:
2013/9/10 Bruce Momjian <bruce@momjian.us>:
I still see that weird behavior in git head:
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".Should I revert the suggested patch?
IIRC the patch was never applied, the reversion candidate is the existing
commit 0725065b.
I reverted 0725065b. AFAICT there is no interest in making \s produce
a reliable full path name. There was some interest in making \cd tell
you where it'd chdir'd to, but that would be a separate patch.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers