Enhance localedef --list-archive option.

The localedef --list-archive option claims that it can
accept a [file] argument and list the contents of that
archive. The support was never implemented. This patch
adds that support and allows --list-archive to work as
expected. You can now use localedef to list the contents
of arbitrary locale archives by using:
./localedef --list-archive file
This commit is contained in:
Carlos O'Donell 2013-10-18 23:41:30 -04:00
parent de5d4f4c8a
commit 484c12fb1e
6 changed files with 44 additions and 10 deletions

View File

@ -1,3 +1,19 @@
2013-10-18 Carlos O'Donell <carlos@redhat.com>
* locale/locarchive.h (struct locarhandle): Add fname.
* locale/programs/localedef.c (main): Pass ARGV[remaining]
if an optional argument was specified to --list-archive,
otherwise NULL.
* locale/programs/locarchive.c (show_archive_content): Take new
argument fname and pass it via ah.fname to open_archive.
* locale/programs/localedef.h: Update decl.
(open_archive): If AH->fname is non-null, open that file
rather than the default file name, and don't ignore ENOENT.
(create_archive): Set AH.fname to NULL.
(delete_locales_from_archive): Likewise.
(add_locales_to_archive): Likewise.
* locale/programs/locfile.c (write_all_categories): Likewise.
2013-10-18 Joseph Myers <joseph@codesourcery.com> 2013-10-18 Joseph Myers <joseph@codesourcery.com>
Aldy Hernandez <aldyh@redhat.com> Aldy Hernandez <aldyh@redhat.com>

View File

@ -80,6 +80,8 @@ struct locrecent
struct locarhandle struct locarhandle
{ {
/* Full path to the locale archive file. */
const char *fname;
int fd; int fd;
void *addr; void *addr;
size_t mmaped; size_t mmaped;

View File

@ -209,7 +209,7 @@ main (int argc, char *argv[])
/* Handle a few special cases. */ /* Handle a few special cases. */
if (list_archive) if (list_archive)
show_archive_content (verbose); show_archive_content (remaining > 1 ? argv[remaining] : NULL, verbose);
if (add_to_archive) if (add_to_archive)
return add_locales_to_archive (argc - remaining, &argv[remaining], return add_locales_to_archive (argc - remaining, &argv[remaining],
replace_archive); replace_archive);

View File

@ -170,7 +170,9 @@ extern int add_locales_to_archive (size_t nlist, char *list[], bool replace);
/* Removed named locales from archive. */ /* Removed named locales from archive. */
extern int delete_locales_from_archive (size_t nlist, char *list[]); extern int delete_locales_from_archive (size_t nlist, char *list[]);
/* List content of locale archive. */ /* List content of locale archive. If FNAME is non-null use that as
extern void show_archive_content (int verbose) __attribute__ ((noreturn)); the locale archive to list, otherwise the default. */
extern void show_archive_content (const char *fname,
int verbose) __attribute__ ((noreturn));
#endif /* localedef.h */ #endif /* localedef.h */

View File

@ -223,6 +223,7 @@ create_archive (const char *archivefname, struct locarhandle *ah)
_("cannot change mode of new locale archive")); _("cannot change mode of new locale archive"));
} }
ah->fname = NULL;
ah->fd = fd; ah->fd = fd;
ah->mmap_base = mmap_base; ah->mmap_base = mmap_base;
ah->mmap_len = mmap_len; ah->mmap_len = mmap_len;
@ -562,11 +563,17 @@ open_archive (struct locarhandle *ah, bool readonly)
struct locarhead head; struct locarhead head;
int retry = 0; int retry = 0;
size_t prefix_len = output_prefix ? strlen (output_prefix) : 0; size_t prefix_len = output_prefix ? strlen (output_prefix) : 0;
char archivefname[prefix_len + sizeof (ARCHIVE_NAME)]; char default_fname[prefix_len + sizeof (ARCHIVE_NAME)];
char *archivefname = ah->fname;
/* If ah has a non-NULL fname open that otherwise open the default. */
if (archivefname == NULL)
{
archivefname = default_fname;
if (output_prefix) if (output_prefix)
memcpy (archivefname, output_prefix, prefix_len); memcpy (archivefname, output_prefix, prefix_len);
strcpy (archivefname + prefix_len, ARCHIVE_NAME); strcpy (archivefname + prefix_len, ARCHIVE_NAME);
}
while (1) while (1)
{ {
@ -574,8 +581,11 @@ open_archive (struct locarhandle *ah, bool readonly)
fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR); fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
if (fd == -1) if (fd == -1)
{ {
/* Maybe the file does not yet exist. */ /* Maybe the file does not yet exist? If we are opening
if (errno == ENOENT) the default locale archive we ignore the failure and
list an empty archive, otherwise we print an error
and exit. */
if (errno == ENOENT && archivefname == default_fname)
{ {
if (readonly) if (readonly)
{ {
@ -1329,6 +1339,7 @@ add_locales_to_archive (nlist, list, replace)
/* Open the archive. This call never returns if we cannot /* Open the archive. This call never returns if we cannot
successfully open the archive. */ successfully open the archive. */
ah.fname = NULL;
open_archive (&ah, false); open_archive (&ah, false);
while (nlist-- > 0) while (nlist-- > 0)
@ -1528,6 +1539,7 @@ delete_locales_from_archive (nlist, list)
/* Open the archive. This call never returns if we cannot /* Open the archive. This call never returns if we cannot
successfully open the archive. */ successfully open the archive. */
ah.fname = NULL;
open_archive (&ah, false); open_archive (&ah, false);
head = ah.addr; head = ah.addr;
@ -1617,7 +1629,7 @@ dataentcmp (const void *a, const void *b)
void void
show_archive_content (int verbose) show_archive_content (const char *fname, int verbose)
{ {
struct locarhandle ah; struct locarhandle ah;
struct locarhead *head; struct locarhead *head;
@ -1627,6 +1639,7 @@ show_archive_content (int verbose)
/* Open the archive. This call never returns if we cannot /* Open the archive. This call never returns if we cannot
successfully open the archive. */ successfully open the archive. */
ah.fname = fname;
open_archive (&ah, true); open_archive (&ah, true);
head = ah.addr; head = ah.addr;

View File

@ -343,6 +343,7 @@ write_all_categories (struct localedef_t *definitions,
/* Open the archive. This call never returns if we cannot /* Open the archive. This call never returns if we cannot
successfully open the archive. */ successfully open the archive. */
ah.fname = NULL;
open_archive (&ah, false); open_archive (&ah, false);
if (add_locale_to_archive (&ah, locname, to_archive, true) != 0) if (add_locale_to_archive (&ah, locname, to_archive, true) != 0)