forked from Mirrors/flatpak-builder
Move migrate_locales to builder-utils.c
parent
d5d47aa458
commit
b44bbc13c3
|
@ -737,103 +737,6 @@ builder_module_handle_debuginfo (BuilderModule *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
migrate_locale_dir (GFile *source_dir,
|
||||
GFile *separate_dir,
|
||||
const char *subdir,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GFileEnumerator) dir_enum = NULL;
|
||||
GFileInfo *next;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
dir_enum = g_file_enumerate_children (source_dir, "standard::name,standard::type",
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
NULL, NULL);
|
||||
if (!dir_enum)
|
||||
return TRUE;
|
||||
|
||||
while ((next = g_file_enumerator_next_file (dir_enum, NULL, &temp_error)))
|
||||
{
|
||||
g_autoptr(GFileInfo) child_info = next;
|
||||
g_autoptr(GFile) child = NULL;
|
||||
g_autoptr(GFile) locale_subdir = NULL;
|
||||
|
||||
child = g_file_get_child (source_dir, g_file_info_get_name (child_info));
|
||||
|
||||
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
g_autoptr(GFile) child = NULL;
|
||||
const char *name = g_file_info_get_name (child_info);
|
||||
g_autofree char *language = g_strdup (name);
|
||||
g_autofree char *relative = NULL;
|
||||
g_autofree char *target = NULL;
|
||||
char *c;
|
||||
|
||||
c = strchr (language, '@');
|
||||
if (c != NULL)
|
||||
*c = 0;
|
||||
c = strchr (language, '_');
|
||||
if (c != NULL)
|
||||
*c = 0;
|
||||
|
||||
/* We ship english and C locales always */
|
||||
if (strcmp (language, "C") == 0 ||
|
||||
strcmp (language, "en") == 0)
|
||||
continue;
|
||||
|
||||
child = g_file_get_child (source_dir, g_file_info_get_name (child_info));
|
||||
|
||||
relative = g_build_filename (language, subdir, name, NULL);
|
||||
locale_subdir = g_file_resolve_relative_path (separate_dir, relative);
|
||||
if (!gs_file_ensure_directory (locale_subdir, TRUE,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
if (!xdg_app_cp_a (child, locale_subdir,
|
||||
XDG_APP_CP_FLAGS_MERGE | XDG_APP_CP_FLAGS_MOVE,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
target = g_build_filename ("../../share/runtime/locale", relative, NULL);
|
||||
|
||||
if (!g_file_make_symbolic_link (child, target,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (temp_error != NULL)
|
||||
{
|
||||
g_propagate_error (error, temp_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
migrate_locale_dirs (GFile *root_dir,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GFile) separate_dir = NULL;
|
||||
g_autoptr(GFile) lib_locale_dir = NULL;
|
||||
g_autoptr(GFile) share_locale_dir = NULL;
|
||||
|
||||
lib_locale_dir = g_file_resolve_relative_path (root_dir, "lib/locale");
|
||||
share_locale_dir = g_file_resolve_relative_path (root_dir, "share/locale");
|
||||
separate_dir = g_file_resolve_relative_path (root_dir, "share/runtime/locale");
|
||||
|
||||
if (!migrate_locale_dir (lib_locale_dir, separate_dir, "lib", error))
|
||||
return FALSE;
|
||||
|
||||
if (!migrate_locale_dir (share_locale_dir, separate_dir, "share", error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
builder_module_build (BuilderModule *self,
|
||||
BuilderCache *cache,
|
||||
|
@ -1091,7 +994,7 @@ builder_module_build (BuilderModule *self,
|
|||
else
|
||||
root_dir = g_file_get_child (app_dir, "files");
|
||||
|
||||
if (!migrate_locale_dirs (root_dir, error))
|
||||
if (!builder_migrate_locale_dirs (root_dir, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -235,3 +235,100 @@ gboolean directory_is_empty (const char *path)
|
|||
|
||||
return empty;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
migrate_locale_dir (GFile *source_dir,
|
||||
GFile *separate_dir,
|
||||
const char *subdir,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GFileEnumerator) dir_enum = NULL;
|
||||
GFileInfo *next;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
dir_enum = g_file_enumerate_children (source_dir, "standard::name,standard::type",
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
NULL, NULL);
|
||||
if (!dir_enum)
|
||||
return TRUE;
|
||||
|
||||
while ((next = g_file_enumerator_next_file (dir_enum, NULL, &temp_error)))
|
||||
{
|
||||
g_autoptr(GFileInfo) child_info = next;
|
||||
g_autoptr(GFile) child = NULL;
|
||||
g_autoptr(GFile) locale_subdir = NULL;
|
||||
|
||||
child = g_file_get_child (source_dir, g_file_info_get_name (child_info));
|
||||
|
||||
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
g_autoptr(GFile) child = NULL;
|
||||
const char *name = g_file_info_get_name (child_info);
|
||||
g_autofree char *language = g_strdup (name);
|
||||
g_autofree char *relative = NULL;
|
||||
g_autofree char *target = NULL;
|
||||
char *c;
|
||||
|
||||
c = strchr (language, '@');
|
||||
if (c != NULL)
|
||||
*c = 0;
|
||||
c = strchr (language, '_');
|
||||
if (c != NULL)
|
||||
*c = 0;
|
||||
|
||||
/* We ship english and C locales always */
|
||||
if (strcmp (language, "C") == 0 ||
|
||||
strcmp (language, "en") == 0)
|
||||
continue;
|
||||
|
||||
child = g_file_get_child (source_dir, g_file_info_get_name (child_info));
|
||||
|
||||
relative = g_build_filename (language, subdir, name, NULL);
|
||||
locale_subdir = g_file_resolve_relative_path (separate_dir, relative);
|
||||
if (!gs_file_ensure_directory (locale_subdir, TRUE,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
if (!xdg_app_cp_a (child, locale_subdir,
|
||||
XDG_APP_CP_FLAGS_MERGE | XDG_APP_CP_FLAGS_MOVE,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
target = g_build_filename ("../../share/runtime/locale", relative, NULL);
|
||||
|
||||
if (!g_file_make_symbolic_link (child, target,
|
||||
NULL, error))
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (temp_error != NULL)
|
||||
{
|
||||
g_propagate_error (error, temp_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
builder_migrate_locale_dirs (GFile *root_dir,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GFile) separate_dir = NULL;
|
||||
g_autoptr(GFile) lib_locale_dir = NULL;
|
||||
g_autoptr(GFile) share_locale_dir = NULL;
|
||||
|
||||
lib_locale_dir = g_file_resolve_relative_path (root_dir, "lib/locale");
|
||||
share_locale_dir = g_file_resolve_relative_path (root_dir, "share/locale");
|
||||
separate_dir = g_file_resolve_relative_path (root_dir, "share/runtime/locale");
|
||||
|
||||
if (!migrate_locale_dir (lib_locale_dir, separate_dir, "lib", error))
|
||||
return FALSE;
|
||||
|
||||
if (!migrate_locale_dir (share_locale_dir, separate_dir, "share", error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ void xdg_app_collect_matches_for_path_pattern (const char *path,
|
|||
const char *pattern,
|
||||
const char *add_prefix,
|
||||
GHashTable *to_remove_ht);
|
||||
gboolean builder_migrate_locale_dirs (GFile *root_dir,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in New Issue