mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Allow a major PG version psql .psqlrc file to be used if a minor
matching version file does not exist. This avoids needing to rename .psqlrc files after minor version upgrades.
This commit is contained in:
parent
d26e1ebaf5
commit
2795592e52
@ -3332,8 +3332,10 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
|
|||||||
Both the system-wide <filename>psqlrc</filename> file and the user's
|
Both the system-wide <filename>psqlrc</filename> file and the user's
|
||||||
<filename>~/.psqlrc</filename> file can be made version-specific
|
<filename>~/.psqlrc</filename> file can be made version-specific
|
||||||
by appending a dash and the <productname>PostgreSQL</productname>
|
by appending a dash and the <productname>PostgreSQL</productname>
|
||||||
release number, for example <filename>~/.psqlrc-&version;</filename>.
|
major or minor release number, for example
|
||||||
A matching version-specific file will be read in preference to a
|
<filename>~/.psqlrc-9.2</filename> or
|
||||||
|
<filename>~/.psqlrc-9.2.5</filename>. The most specific
|
||||||
|
version-matching file will be read in preference to a
|
||||||
non-version-specific file.
|
non-version-specific file.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
@ -594,20 +594,27 @@ process_psqlrc(char *argv0)
|
|||||||
static void
|
static void
|
||||||
process_psqlrc_file(char *filename)
|
process_psqlrc_file(char *filename)
|
||||||
{
|
{
|
||||||
char *psqlrc;
|
char *psqlrc_minor, *psqlrc_major;
|
||||||
|
|
||||||
#if defined(WIN32) && (!defined(__MINGW32__))
|
#if defined(WIN32) && (!defined(__MINGW32__))
|
||||||
#define R_OK 4
|
#define R_OK 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
psqlrc = pg_malloc(strlen(filename) + 1 + strlen(PG_VERSION) + 1);
|
psqlrc_minor = pg_malloc(strlen(filename) + 1 + strlen(PG_VERSION) + 1);
|
||||||
sprintf(psqlrc, "%s-%s", filename, PG_VERSION);
|
sprintf(psqlrc_minor, "%s-%s", filename, PG_VERSION);
|
||||||
|
psqlrc_major = pg_malloc(strlen(filename) + 1 + strlen(PG_MAJORVERSION) + 1);
|
||||||
|
sprintf(psqlrc_major, "%s-%s", filename, PG_MAJORVERSION);
|
||||||
|
|
||||||
if (access(psqlrc, R_OK) == 0)
|
/* check for minor version first, then major, then no version */
|
||||||
(void) process_file(psqlrc, false, false);
|
if (access(psqlrc_minor, R_OK) == 0)
|
||||||
|
(void) process_file(psqlrc_minor, false, false);
|
||||||
|
else if (access(psqlrc_major, R_OK) == 0)
|
||||||
|
(void) process_file(psqlrc_major, false, false);
|
||||||
else if (access(filename, R_OK) == 0)
|
else if (access(filename, R_OK) == 0)
|
||||||
(void) process_file(filename, false, false);
|
(void) process_file(filename, false, false);
|
||||||
free(psqlrc);
|
|
||||||
|
free(psqlrc_minor);
|
||||||
|
free(psqlrc_major);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user