diff --git a/libfwupdplugin/README.md b/libfwupdplugin/README.md index 19a5031c7..647bcde39 100644 --- a/libfwupdplugin/README.md +++ b/libfwupdplugin/README.md @@ -79,3 +79,4 @@ Remember: Plugins should be upstream! * `fu_common_set_firmware_search_path()`: Use `fu_kernel_set_firmware_search_path` instead. * `fu_common_reset_firmware_search_path()`: Use `fu_kernel_reset_firmware_search_path` instead. * `fu_common_firmware_builder()`: You should not be using this. +* `fu_common_realpath()`: You should not be using this. diff --git a/libfwupdplugin/fu-common.c b/libfwupdplugin/fu-common.c index 50ead1d7b..380461e0c 100644 --- a/libfwupdplugin/fu-common.c +++ b/libfwupdplugin/fu-common.c @@ -663,48 +663,6 @@ fu_common_dump_bytes(const gchar *log_domain, const gchar *title, GBytes *bytes) fu_common_dump_raw(log_domain, title, data, len); } -/** - * fu_common_realpath: - * @filename: a filename - * @error: (nullable): optional return location for an error - * - * Finds the canonicalized absolute filename for a path. - * - * Returns: a filename, or %NULL if invalid or not found - * - * Since: 1.2.6 - **/ -gchar * -fu_common_realpath(const gchar *filename, GError **error) -{ - char full_tmp[PATH_MAX]; - - g_return_val_if_fail(filename != NULL, NULL); - g_return_val_if_fail(error == NULL || *error == NULL, NULL); - -#ifdef HAVE_REALPATH - if (realpath(filename, full_tmp) == NULL) { -#else - if (_fullpath(full_tmp, filename, sizeof(full_tmp)) == NULL) { -#endif - g_set_error(error, - G_IO_ERROR, - G_IO_ERROR_INVALID_DATA, - "cannot resolve path: %s", - strerror(errno)); - return NULL; - } - if (!g_file_test(full_tmp, G_FILE_TEST_EXISTS)) { - g_set_error(error, - G_IO_ERROR, - G_IO_ERROR_INVALID_DATA, - "cannot find path: %s", - full_tmp); - return NULL; - } - return g_strdup(full_tmp); -} - /** * fu_common_fnmatch: * @pattern: a glob pattern, e.g. `*foo*` diff --git a/libfwupdplugin/fu-common.h b/libfwupdplugin/fu-common.h index dde7c932d..a68645bba 100644 --- a/libfwupdplugin/fu-common.h +++ b/libfwupdplugin/fu-common.h @@ -171,8 +171,6 @@ typedef enum { gchar * fu_common_get_path(FuPathKind path_kind); -gchar * -fu_common_realpath(const gchar *filename, GError **error) G_GNUC_WARN_UNUSED_RESULT; GPtrArray * fu_common_filename_glob(const gchar *directory, const gchar *pattern, diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 418a2830a..378b33b37 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -291,7 +291,6 @@ LIBFWUPDPLUGIN_1.2.5 { LIBFWUPDPLUGIN_1.2.6 { global: - fu_common_realpath; fu_device_activate; fu_device_get_firmware_size_max; fu_device_get_firmware_size_min; diff --git a/src/fu-engine.c b/src/fu-engine.c index 1d6c4de7d..e25dfbfa6 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -13,6 +13,7 @@ #include #endif #include +#include #include #ifdef HAVE_UTSNAME_H #include @@ -2096,6 +2097,39 @@ fu_engine_is_running_offline(FuEngine *self) #endif } +#ifdef HAVE_GIO_UNIX +static gchar * +fu_realpath(const gchar *filename, GError **error) +{ + char full_tmp[PATH_MAX]; + + g_return_val_if_fail(filename != NULL, NULL); + g_return_val_if_fail(error == NULL || *error == NULL, NULL); + +#ifdef HAVE_REALPATH + if (realpath(filename, full_tmp) == NULL) { +#else + if (_fullpath(full_tmp, filename, sizeof(full_tmp)) == NULL) { +#endif + g_set_error(error, + G_IO_ERROR, + G_IO_ERROR_INVALID_DATA, + "cannot resolve path: %s", + strerror(errno)); + return NULL; + } + if (!g_file_test(full_tmp, G_FILE_TEST_EXISTS)) { + g_set_error(error, + G_IO_ERROR, + G_IO_ERROR_INVALID_DATA, + "cannot find path: %s", + full_tmp); + return NULL; + } + return g_strdup(full_tmp); +} +#endif + static gboolean fu_engine_offline_setup(GError **error) { @@ -2108,7 +2142,7 @@ fu_engine_offline_setup(GError **error) g_return_val_if_fail(error == NULL || *error == NULL, FALSE); /* does already exist */ - filename = fu_common_realpath(trigger, NULL); + filename = fu_realpath(trigger, NULL); if (g_strcmp0(filename, symlink_target) == 0) { g_debug("%s already points to %s, skipping creation", trigger, symlink_target); return TRUE;