[gimp/soc-2011-seamless-clone2] libgimpbase: clean up the linux relocation code
- From: Clayton Walker <claytonw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2011-seamless-clone2] libgimpbase: clean up the linux relocation code
- Date: Wed, 8 May 2013 14:59:18 +0000 (UTC)
commit 33837de14f949afc78e8ff41a47c5ab96e1298d6
Author: Michael Natterer <mitch gimp org>
Date: Sun Jan 27 22:26:29 2013 +0100
libgimpbase: clean up the linux relocation code
by removing all but the toplevel prefix getter from gimpreloc.c It was
1) confusing 2) sometimes trying to subsitute the runtime prefix twice
and 3) sometimes ignoring configure-given directories within the
configure-prefix. This should all be fixed now, and done in one less
place.
libgimpbase/gimpenv.c | 46 ++++++--
libgimpbase/gimpreloc.c | 280 -----------------------------------------------
libgimpbase/gimpreloc.h | 17 +--
3 files changed, 37 insertions(+), 306 deletions(-)
---
diff --git a/libgimpbase/gimpenv.c b/libgimpbase/gimpenv.c
index 836ca8f..23fe962 100644
--- a/libgimpbase/gimpenv.c
+++ b/libgimpbase/gimpenv.c
@@ -91,7 +91,8 @@ static const char* datadir = DATADIR;
static gchar * gimp_env_get_dir (const gchar *gimp_env_name,
- const gchar *env_dir);
+ const gchar *compile_time_dir,
+ const gchar *relative_subdir);
#ifdef G_OS_WIN32
static gchar * get_special_folder (gint csidl);
#endif
@@ -132,7 +133,9 @@ gimp_env_init (gboolean plug_in)
/* Set $LD_LIBRARY_PATH to ensure that plugins can be loaded. */
const gchar *ldpath = g_getenv ("LD_LIBRARY_PATH");
- gchar *libdir = _gimp_reloc_find_lib_dir (NULL);
+ gchar *libdir = g_build_filename (gimp_installation_directory (),
+ "lib",
+ NULL);
if (ldpath && *ldpath)
{
@@ -487,9 +490,12 @@ gimp_data_directory (void)
if (! gimp_data_dir)
{
- gchar *tmp = _gimp_reloc_find_data_dir (DATADIR);
+ gchar *tmp = g_build_filename ("share",
+ GIMP_PACKAGE,
+ GIMP_DATA_VERSION,
+ NULL);
- gimp_data_dir = gimp_env_get_dir ("GIMP2_DATADIR", tmp);
+ gimp_data_dir = gimp_env_get_dir ("GIMP2_DATADIR", DATADIR, tmp);
g_free (tmp);
}
@@ -522,10 +528,13 @@ gimp_locale_directory (void)
if (! gimp_locale_dir)
{
- gchar *tmp = _gimp_reloc_find_locale_dir (LOCALEDIR);
+ gchar *tmp = g_build_filename ("share",
+ "locale",
+ NULL);
- gimp_locale_dir = gimp_env_get_dir ("GIMP2_LOCALEDIR", tmp);
+ gimp_locale_dir = gimp_env_get_dir ("GIMP2_LOCALEDIR", LOCALEDIR, tmp);
g_free (tmp);
+
#ifdef G_OS_WIN32
tmp = g_win32_locale_filename_from_utf8 (gimp_locale_dir);
g_free (gimp_locale_dir);
@@ -559,9 +568,12 @@ gimp_sysconf_directory (void)
if (! gimp_sysconf_dir)
{
- gchar *tmp = _gimp_reloc_find_etc_dir (SYSCONFDIR);
+ gchar *tmp = g_build_filename ("etc",
+ GIMP_PACKAGE,
+ GIMP_SYSCONF_VERSION,
+ NULL);
- gimp_sysconf_dir = gimp_env_get_dir ("GIMP2_SYSCONFDIR", tmp);
+ gimp_sysconf_dir = gimp_env_get_dir ("GIMP2_SYSCONFDIR", SYSCONFDIR, tmp);
g_free (tmp);
}
@@ -608,9 +620,12 @@ gimp_plug_in_directory (void)
if (! gimp_plug_in_dir)
{
- gchar *tmp = _gimp_reloc_find_plugin_dir (PLUGINDIR);
+ gchar *tmp = g_build_filename ("lib",
+ GIMP_PACKAGE,
+ GIMP_PLUGIN_VERSION,
+ NULL);
- gimp_plug_in_dir = gimp_env_get_dir ("GIMP2_PLUGINDIR", tmp);
+ gimp_plug_in_dir = gimp_env_get_dir ("GIMP2_PLUGINDIR", PLUGINDIR, tmp);
g_free (tmp);
}
@@ -903,7 +918,8 @@ gimp_path_get_user_writable_dir (GList *path)
static gchar *
gimp_env_get_dir (const gchar *gimp_env_name,
- const gchar *env_dir)
+ const gchar *compile_time_dir,
+ const gchar *relative_subdir)
{
const gchar *env = g_getenv (gimp_env_name);
@@ -915,12 +931,16 @@ gimp_env_get_dir (const gchar *gimp_env_name,
return g_strdup (env);
}
- else
+ else if (compile_time_dir)
{
- gchar *retval = g_strdup (env_dir);
+ gchar *retval = g_strdup (compile_time_dir);
gimp_path_runtime_fix (&retval);
return retval;
}
+
+ return g_build_filename (gimp_installation_directory (),
+ relative_subdir,
+ NULL);
}
diff --git a/libgimpbase/gimpreloc.c b/libgimpbase/gimpreloc.c
index 79b9909..763f3cc 100644
--- a/libgimpbase/gimpreloc.c
+++ b/libgimpbase/gimpreloc.c
@@ -383,58 +383,6 @@ set_gerror (GError **error, GimpBinrelocInitError errcode)
}
-/* Find the canonical filename of the current application.
- *
- * @param default_exe A default filename which will be used as fallback.
- * @returns A string containing the application's canonical filename,
- * which must be freed when no longer necessary. If BinReloc is
- * not initialized, or if the initialization function failed,
- * then a copy of default_exe will be returned. If default_exe
- * is NULL, then NULL will be returned.
- */
-gchar *
-_gimp_reloc_find_exe (const gchar *default_exe)
-{
- if (exe == NULL) {
- /* BinReloc is not initialized. */
- if (default_exe != NULL)
- return g_strdup (default_exe);
- else
- return NULL;
- }
- return g_strdup (exe);
-}
-
-
-/* Locate the directory in which the current application is installed.
- *
- * The prefix is generated by the following pseudo-code evaluation:
- * \code
- * dirname(exename)
- * \endcode
- *
- * @param default_dir A default directory which will used as fallback.
- * @return A string containing the directory, which must be freed when no
- * longer necessary. If BinReloc is not initialized, or if the
- * initialization function failed, then a copy of default_dir
- * will be returned. If default_dir is NULL, then NULL will be
- * returned.
- */
-gchar *
-_gimp_reloc_find_exe_dir (const gchar *default_dir)
-{
- if (exe == NULL) {
- /* BinReloc not initialized. */
- if (default_dir != NULL)
- return g_strdup (default_dir);
- else
- return NULL;
- }
-
- return g_path_get_dirname (exe);
-}
-
-
/* Locate the prefix in which the current application is installed.
*
* The prefix is generated by the following pseudo-code evaluation:
@@ -467,231 +415,3 @@ _gimp_reloc_find_prefix (const gchar *default_prefix)
g_free (dir1);
return dir2;
}
-
-
-/* Locate the application's binary folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/bin"
- * \endcode
- *
- * @param default_bin_dir A default path which will used as fallback.
- * @return A string containing the bin folder's path, which must be freed when
- * no longer necessary. If BinReloc is not initialized, or if the
- * initialization function failed, then a copy of default_bin_dir will
- * be returned. If default_bin_dir is NULL, then NULL will be returned.
- */
-gchar *
-_gimp_reloc_find_bin_dir (const gchar *default_bin_dir)
-{
- gchar *prefix, *dir;
-
- prefix = _gimp_reloc_find_prefix (NULL);
- if (prefix == NULL) {
- /* BinReloc not initialized. */
- if (default_bin_dir != NULL)
- return g_strdup (default_bin_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (prefix, "bin", NULL);
- g_free (prefix);
- return dir;
-}
-
-
-/* Locate the application's data folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/share/" + GIMP_PACKAGE + "/" + GIMP_DATA_VERSION
- * \endcode
- *
- * @param default_data_dir A default path which will used as fallback.
- * @return A string containing the data folder's path, which must be freed when
- * no longer necessary. If BinReloc is not initialized, or if the
- * initialization function failed, then a copy of default_data_dir
- * will be returned. If default_data_dir is NULL, then NULL will be
- * returned.
- */
-gchar *
-_gimp_reloc_find_data_dir (const gchar *default_data_dir)
-{
- gchar *prefix, *dir;
-
- prefix = _gimp_reloc_find_prefix (NULL);
- if (prefix == NULL) {
- /* BinReloc not initialized. */
- if (default_data_dir != NULL)
- return g_strdup (default_data_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (prefix, "share",
- GIMP_PACKAGE,
- GIMP_DATA_VERSION,
- NULL);
- g_free (prefix);
- return dir;
-}
-
-gchar *
-_gimp_reloc_find_plugin_dir (const gchar *default_plugin_dir)
-{
- gchar *libdir, *dir;
-
- libdir = _gimp_reloc_find_lib_dir (NULL);
- if (libdir == NULL) {
- /* BinReloc not initialized. */
- if (default_plugin_dir != NULL)
- return g_strdup (default_plugin_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (libdir,
- GIMP_PACKAGE,
- GIMP_PLUGIN_VERSION,
- NULL);
- g_free (libdir);
- return dir;
-}
-
-
-/* Locate the application's localization folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/share/locale"
- * \endcode
- *
- * @param default_locale_dir A default path which will used as fallback.
- * @return A string containing the localization folder's path, which must be freed when
- * no longer necessary. If BinReloc is not initialized, or if the
- * initialization function failed, then a copy of default_locale_dir will be returned.
- * If default_locale_dir is NULL, then NULL will be returned.
- */
-gchar *
-_gimp_reloc_find_locale_dir (const gchar *default_locale_dir)
-{
- gchar *data_dir, *dir;
-
- data_dir = _gimp_reloc_find_data_dir (NULL);
- if (data_dir == NULL) {
- /* BinReloc not initialized. */
- if (default_locale_dir != NULL)
- return g_strdup (default_locale_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (data_dir, "locale", NULL);
- g_free (data_dir);
- return dir;
-}
-
-
-/* Locate the application's library folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/lib"
- * \endcode
- *
- * @param default_lib_dir A default path which will used as fallback.
- * @return A string containing the library folder's path, which must be freed when
- * no longer necessary. If BinReloc is not initialized, or if the
- * initialization function failed, then a copy of default_lib_dir will be returned.
- * If default_lib_dir is NULL, then NULL will be returned.
- */
-gchar *
-_gimp_reloc_find_lib_dir (const gchar *default_lib_dir)
-{
- gchar *prefix, *dir;
-
- prefix = _gimp_reloc_find_prefix (NULL);
- if (prefix == NULL) {
- /* BinReloc not initialized. */
- if (default_lib_dir != NULL)
- return g_strdup (default_lib_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (prefix, "lib", NULL);
- g_free (prefix);
- return dir;
-}
-
-
-/* Locate the application's libexec folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/libexec"
- * \endcode
- *
- * @param default_libexec_dir A default path which will used as fallback.
- * @return A string containing the libexec folder's path, which must be freed when
- * no longer necessary. If BinReloc is not initialized, or if the initialization
- * function failed, then a copy of default_libexec_dir will be returned.
- * If default_libexec_dir is NULL, then NULL will be returned.
- */
-gchar *
-_gimp_reloc_find_libexec_dir (const gchar *default_libexec_dir)
-{
- gchar *prefix, *dir;
-
- prefix = _gimp_reloc_find_prefix (NULL);
- if (prefix == NULL) {
- /* BinReloc not initialized. */
- if (default_libexec_dir != NULL)
- return g_strdup (default_libexec_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (prefix, "libexec", NULL);
- g_free (prefix);
- return dir;
-}
-
-
-/* Locate the application's configuration files folder.
- *
- * The path is generated by the following pseudo-code evaluation:
- * \code
- * prefix + "/etc/" + GIMP_PACKAGE + "/" + GIMP_SYSCONF_VERSION
- * \endcode
- *
- * @param default_etc_dir A default path which will used as fallback.
- * @return A string containing the etc folder's path, which must be freed when
- * no longer necessary. If BinReloc is not initialized, or if the
- * initialization function failed, then a copy of default_etc_dir
- * will be returned. If default_etc_dir is NULL, then NULL will be
- * returned.
- */
-gchar *
-_gimp_reloc_find_etc_dir (const gchar *default_etc_dir)
-{
- gchar *prefix, *dir;
-
- prefix = _gimp_reloc_find_prefix (NULL);
- if (prefix == NULL) {
- /* BinReloc not initialized. */
- if (default_etc_dir != NULL)
- return g_strdup (default_etc_dir);
- else
- return NULL;
- }
-
- dir = g_build_filename (prefix, "etc",
- GIMP_PACKAGE,
- GIMP_SYSCONF_VERSION,
- NULL);
- g_free (prefix);
- return dir;
-}
diff --git a/libgimpbase/gimpreloc.h b/libgimpbase/gimpreloc.h
index ed98be8..a7af912 100644
--- a/libgimpbase/gimpreloc.h
+++ b/libgimpbase/gimpreloc.h
@@ -35,19 +35,10 @@ typedef enum
} GimpBinrelocInitError;
-G_GNUC_INTERNAL gboolean _gimp_reloc_init (GError **error);
-G_GNUC_INTERNAL gboolean _gimp_reloc_init_lib (GError **error);
-
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_exe (const gchar *default_exe);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_exe_dir (const gchar *default_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_prefix (const gchar *default_prefix);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_bin_dir (const gchar *default_bin_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_data_dir (const gchar *default_data_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_plugin_dir (const gchar *default_plugin_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_locale_dir (const gchar *default_locale_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_lib_dir (const gchar *default_lib_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_libexec_dir (const gchar *default_libexec_dir);
-G_GNUC_INTERNAL gchar * _gimp_reloc_find_etc_dir (const gchar *default_etc_dir);
+G_GNUC_INTERNAL gboolean _gimp_reloc_init (GError **error);
+G_GNUC_INTERNAL gboolean _gimp_reloc_init_lib (GError **error);
+
+G_GNUC_INTERNAL gchar * _gimp_reloc_find_prefix (const gchar *default_prefix);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]