Skip to content

Commit d4c810d

Browse files
committed
Modify initdb to complain only when no usable system locales are found.
Per discussion, the original behavior seems too noisy. But if things are so broken that none of the locales reported by "locale -a" are usable, that's probably worth warning about.
1 parent fbc0d07 commit d4c810d

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/bin/initdb/initdb.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ setup_collation(void)
15641564
int i;
15651565
FILE *locale_a_handle;
15661566
char localebuf[NAMEDATALEN];
1567-
int skipped = 0;
1567+
int count = 0;
15681568
PG_CMD_DECL;
15691569
#endif
15701570

@@ -1579,7 +1579,7 @@ setup_collation(void)
15791579

15801580
locale_a_handle = popen_check("locale -a", "r");
15811581
if (!locale_a_handle)
1582-
return;
1582+
return; /* complaint already printed */
15831583

15841584
PG_CMD_OPEN;
15851585

@@ -1597,12 +1597,11 @@ setup_collation(void)
15971597

15981598
len = strlen(localebuf);
15991599

1600-
if (localebuf[len - 1] != '\n')
1600+
if (len == 0 || localebuf[len - 1] != '\n')
16011601
{
16021602
if (debug)
16031603
fprintf(stderr, _("%s: locale name too long, skipped: %s\n"),
16041604
progname, localebuf);
1605-
skipped++;
16061605
continue;
16071606
}
16081607
localebuf[len - 1] = '\0';
@@ -1628,22 +1627,23 @@ setup_collation(void)
16281627
if (debug)
16291628
fprintf(stderr, _("%s: locale name has non-ASCII characters, skipped: %s\n"),
16301629
progname, localebuf);
1631-
skipped++;
16321630
continue;
16331631
}
16341632

16351633
enc = pg_get_encoding_from_locale(localebuf, debug);
16361634
if (enc < 0)
16371635
{
1638-
skipped++;
1639-
continue; /* error message printed by pg_get_encoding_from_locale() */
1636+
/* error message printed by pg_get_encoding_from_locale() */
1637+
continue;
16401638
}
16411639
if (!PG_VALID_BE_ENCODING(enc))
16421640
continue; /* ignore locales for client-only encodings */
16431641
if (enc == PG_SQL_ASCII)
16441642
continue; /* C/POSIX are already in the catalog */
16451643

1646-
PG_CMD_PRINTF2("INSERT INTO tmp_pg_collation (locale, encoding) VALUES ('%s', %d);",
1644+
count++;
1645+
1646+
PG_CMD_PRINTF2("INSERT INTO tmp_pg_collation (locale, encoding) VALUES ('%s', %d);\n",
16471647
escape_quotes(localebuf), enc);
16481648

16491649
/*
@@ -1653,12 +1653,12 @@ setup_collation(void)
16531653
* "en_US" for LATIN1, say.
16541654
*/
16551655
if (normalize_locale_name(alias, localebuf))
1656-
PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('%s', '%s', %d);",
1656+
PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('%s', '%s', %d);\n",
16571657
escape_quotes(alias), escape_quotes(localebuf), enc);
16581658
}
16591659

16601660
/* Add an SQL-standard name */
1661-
PG_CMD_PRINTF1("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('ucs_basic', 'C', %d);", PG_UTF8);
1661+
PG_CMD_PRINTF1("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('ucs_basic', 'C', %d);\n", PG_UTF8);
16621662

16631663
/*
16641664
* When copying collations to the final location, eliminate
@@ -1674,21 +1674,17 @@ setup_collation(void)
16741674
" COALESCE(collname, locale) AS final_collname, "
16751675
" (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog') AS collnamespace, "
16761676
" (SELECT relowner FROM pg_class WHERE relname = 'pg_collation') AS collowner, "
1677-
" encoding, "
1678-
" locale, locale "
1677+
" encoding, locale, locale "
16791678
" FROM tmp_pg_collation"
16801679
" ORDER BY final_collname, collnamespace, encoding, (collname = locale) DESC, locale;\n");
16811680

16821681
pclose(locale_a_handle);
16831682
PG_CMD_CLOSE;
16841683

16851684
check_ok();
1686-
if (skipped && !debug)
1685+
if (count == 0 && !debug)
16871686
{
1688-
printf(ngettext("%d system locale has been omitted because it cannot supported by PostgreSQL.\n",
1689-
"%d system locales have been omitted because they cannot be supported by PostgreSQL.\n",
1690-
skipped),
1691-
skipped);
1687+
printf(_("No usable system locales were found.\n"));
16921688
printf(_("Use the option \"--debug\" to see details.\n"));
16931689
}
16941690
#else /* not HAVE_LOCALE_T */

0 commit comments

Comments
 (0)