diff --git a/contrib/migrate.py b/contrib/migrate.py index bed8f28f3..70dd95fc6 100755 --- a/contrib/migrate.py +++ b/contrib/migrate.py @@ -103,6 +103,14 @@ if __name__ == "__main__": "fu_common_dump_full": "fu_dump_full", "fu_common_dump_bytes": "fu_dump_bytes", "fu_common_error_array_get_best": "fu_engine_error_array_get_best", + "fu_common_get_path": "fu_path_from_kind", + "fu_common_filename_glob": "fu_path_glob", + "fu_common_fnmatch": "fu_path_fnmatch", + "fu_common_rmtree": "fu_path_rmtree", + "fu_common_get_files_recursive": "fu_path_get_files", + "fu_common_mkdir": "fu_path_mkdir", + "fu_common_mkdir_parent": "fu_path_mkdir_parent", + "fu_common_find_program_in_path": "fu_path_find_program", }.items(): if buf.find(old) == -1: continue diff --git a/libfwupdplugin/fu-common-darwin.c b/libfwupdplugin/fu-common-darwin.c index 687fddd31..e92c50b26 100644 --- a/libfwupdplugin/fu-common-darwin.c +++ b/libfwupdplugin/fu-common-darwin.c @@ -20,7 +20,7 @@ fu_common_get_block_devices(GError **error) } gboolean -fu_common_fnmatch_impl(const gchar *pattern, const gchar *str) +fu_path_fnmatch_impl(const gchar *pattern, const gchar *str) { return fnmatch(pattern, str, FNM_NOESCAPE) == 0; } diff --git a/libfwupdplugin/fu-common-freebsd.c b/libfwupdplugin/fu-common-freebsd.c index 777e04175..930ce3e1a 100644 --- a/libfwupdplugin/fu-common-freebsd.c +++ b/libfwupdplugin/fu-common-freebsd.c @@ -16,6 +16,7 @@ #endif #include "fu-common-private.h" +#include "fu-path-private.h" /* bsdisks doesn't provide Manager object */ #define UDISKS_DBUS_PATH "/org/freedesktop/UDisks2" @@ -110,7 +111,7 @@ fu_common_get_block_devices(GError **error) } gboolean -fu_common_fnmatch_impl(const gchar *pattern, const gchar *str) +fu_path_fnmatch_impl(const gchar *pattern, const gchar *str) { #ifdef HAVE_FNMATCH_H return fnmatch(pattern, str, FNM_NOESCAPE) == 0; diff --git a/libfwupdplugin/fu-common-linux.c b/libfwupdplugin/fu-common-linux.c index a5c1017da..3eaed926e 100644 --- a/libfwupdplugin/fu-common-linux.c +++ b/libfwupdplugin/fu-common-linux.c @@ -15,6 +15,7 @@ #endif #include "fu-common-private.h" +#include "fu-path-private.h" #define UDISKS_DBUS_PATH "/org/freedesktop/UDisks2/Manager" #define UDISKS_DBUS_MANAGER_INTERFACE "org.freedesktop.UDisks2.Manager" @@ -88,7 +89,7 @@ fu_common_get_block_devices(GError **error) } gboolean -fu_common_fnmatch_impl(const gchar *pattern, const gchar *str) +fu_path_fnmatch_impl(const gchar *pattern, const gchar *str) { #ifdef HAVE_FNMATCH_H return fnmatch(pattern, str, FNM_NOESCAPE) == 0; diff --git a/libfwupdplugin/fu-common-private.h b/libfwupdplugin/fu-common-private.h index f44aed925..278e37971 100644 --- a/libfwupdplugin/fu-common-private.h +++ b/libfwupdplugin/fu-common-private.h @@ -15,8 +15,6 @@ GPtrArray * fu_common_get_block_devices(GError **error); -gboolean -fu_common_fnmatch_impl(const gchar *pattern, const gchar *str); guint64 fu_common_get_memory_size_impl(void); diff --git a/libfwupdplugin/fu-common-windows.c b/libfwupdplugin/fu-common-windows.c index 2ce3b0d7d..cfcded4fa 100644 --- a/libfwupdplugin/fu-common-windows.c +++ b/libfwupdplugin/fu-common-windows.c @@ -12,6 +12,7 @@ #include #include "fu-common-private.h" +#include "fu-path-private.h" GPtrArray * fu_common_get_block_devices(GError **error) @@ -21,7 +22,7 @@ fu_common_get_block_devices(GError **error) } gboolean -fu_common_fnmatch_impl(const gchar *pattern, const gchar *str) +fu_path_fnmatch_impl(const gchar *pattern, const gchar *str) { g_return_val_if_fail(pattern != NULL, FALSE); g_return_val_if_fail(str != NULL, FALSE); diff --git a/libfwupdplugin/fu-common.c b/libfwupdplugin/fu-common.c index 5e0b5fe39..ea2a34403 100644 --- a/libfwupdplugin/fu-common.c +++ b/libfwupdplugin/fu-common.c @@ -32,494 +32,6 @@ #include "fu-string.h" #include "fu-volume-private.h" -/** - * fu_common_rmtree: - * @directory: a directory name - * @error: (nullable): optional return location for an error - * - * Recursively removes a directory. - * - * Returns: %TRUE for success, %FALSE otherwise - * - * Since: 0.9.7 - **/ -gboolean -fu_common_rmtree(const gchar *directory, GError **error) -{ - const gchar *filename; - g_autoptr(GDir) dir = NULL; - - g_return_val_if_fail(directory != NULL, FALSE); - g_return_val_if_fail(error == NULL || *error == NULL, FALSE); - - /* try to open */ - g_debug("removing %s", directory); - dir = g_dir_open(directory, 0, error); - if (dir == NULL) - return FALSE; - - /* find each */ - while ((filename = g_dir_read_name(dir))) { - g_autofree gchar *src = NULL; - src = g_build_filename(directory, filename, NULL); - if (g_file_test(src, G_FILE_TEST_IS_DIR)) { - if (!fu_common_rmtree(src, error)) - return FALSE; - } else { - if (g_unlink(src) != 0) { - g_set_error(error, - FWUPD_ERROR, - FWUPD_ERROR_INTERNAL, - "Failed to delete: %s", - src); - return FALSE; - } - } - } - if (g_remove(directory) != 0) { - g_set_error(error, - FWUPD_ERROR, - FWUPD_ERROR_INTERNAL, - "Failed to delete: %s", - directory); - return FALSE; - } - return TRUE; -} - -static gboolean -fu_common_get_file_list_internal(GPtrArray *files, const gchar *directory, GError **error) -{ - const gchar *filename; - g_autoptr(GDir) dir = NULL; - - /* try to open */ - dir = g_dir_open(directory, 0, error); - if (dir == NULL) - return FALSE; - - /* find each */ - while ((filename = g_dir_read_name(dir))) { - g_autofree gchar *src = g_build_filename(directory, filename, NULL); - if (g_file_test(src, G_FILE_TEST_IS_DIR)) { - if (!fu_common_get_file_list_internal(files, src, error)) - return FALSE; - } else { - g_ptr_array_add(files, g_steal_pointer(&src)); - } - } - return TRUE; -} - -/** - * fu_common_get_files_recursive: - * @path: a directory name - * @error: (nullable): optional return location for an error - * - * Returns every file found under @directory, and any subdirectory. - * If any path under @directory cannot be accessed due to permissions an error - * will be returned. - * - * Returns: (transfer container) (element-type utf8): array of files, or %NULL for error - * - * Since: 1.0.6 - **/ -GPtrArray * -fu_common_get_files_recursive(const gchar *path, GError **error) -{ - g_autoptr(GPtrArray) files = g_ptr_array_new_with_free_func(g_free); - - g_return_val_if_fail(path != NULL, NULL); - g_return_val_if_fail(error == NULL || *error == NULL, NULL); - - if (!fu_common_get_file_list_internal(files, path, error)) - return NULL; - return g_steal_pointer(&files); -} - -/** - * fu_common_mkdir: - * @dirname: a directory name - * @error: (nullable): optional return location for an error - * - * Creates any required directories, including any parent directories. - * - * Returns: %TRUE for success - * - * Since: 1.7.1 - **/ -gboolean -fu_common_mkdir(const gchar *dirname, GError **error) -{ - g_return_val_if_fail(dirname != NULL, FALSE); - g_return_val_if_fail(error == NULL || *error == NULL, FALSE); - - if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) - g_debug("creating path %s", dirname); - if (g_mkdir_with_parents(dirname, 0755) == -1) { - g_set_error(error, - FWUPD_ERROR, - FWUPD_ERROR_INTERNAL, - "Failed to create '%s': %s", - dirname, - g_strerror(errno)); - return FALSE; - } - return TRUE; -} - -/** - * fu_common_mkdir_parent: - * @filename: a full pathname - * @error: (nullable): optional return location for an error - * - * Creates any required directories, including any parent directories. - * - * Returns: %TRUE for success - * - * Since: 0.9.7 - **/ -gboolean -fu_common_mkdir_parent(const gchar *filename, GError **error) -{ - g_autofree gchar *parent = NULL; - - g_return_val_if_fail(filename != NULL, FALSE); - g_return_val_if_fail(error == NULL || *error == NULL, FALSE); - - parent = g_path_get_dirname(filename); - return fu_common_mkdir(parent, error); -} - -/** - * fu_common_find_program_in_path: - * @basename: the program to search - * @error: (nullable): optional return location for an error - * - * Looks for a program in the PATH variable - * - * Returns: a new #gchar, or %NULL for error - * - * Since: 1.1.2 - **/ -gchar * -fu_common_find_program_in_path(const gchar *basename, GError **error) -{ - gchar *fn = g_find_program_in_path(basename); - if (fn == NULL) { - g_set_error(error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "missing executable %s in PATH", - basename); - return NULL; - } - return fn; -} - -/** - * fu_common_get_win32_basedir: - * - * Gets the base directory that fwupd has been launched from on Windows. - * This is the directory containing all subdirectories (IE 'C:\Program Files (x86)\fwupd\') - * - * Returns: The system path, or %NULL if invalid - * - * Since: 1.7.4 - **/ -static gchar * -fu_common_get_win32_basedir(void) -{ -#ifdef _WIN32 - char drive_buf[_MAX_DRIVE]; - char dir_buf[_MAX_DIR]; - _splitpath(_pgmptr, drive_buf, dir_buf, NULL, NULL); - return g_build_filename(drive_buf, dir_buf, "..", NULL); -#endif - return NULL; -} - -/** - * fu_common_get_path: - * @path_kind: a #FuPathKind e.g. %FU_PATH_KIND_DATADIR_PKG - * - * Gets a fwupd-specific system path. These can be overridden with various - * environment variables, for instance %FWUPD_DATADIR. - * - * Returns: a system path, or %NULL if invalid - * - * Since: 1.0.8 - **/ -gchar * -fu_common_get_path(FuPathKind path_kind) -{ - const gchar *tmp; - g_autofree gchar *basedir = NULL; - - switch (path_kind) { - /* /var */ - case FU_PATH_KIND_LOCALSTATEDIR: - tmp = g_getenv("FWUPD_LOCALSTATEDIR"); - if (tmp != NULL) - return g_strdup(tmp); -#ifdef _WIN32 - return g_build_filename(g_getenv("USERPROFILE"), - PACKAGE_NAME, - FWUPD_LOCALSTATEDIR, - NULL); -#else - tmp = g_getenv("SNAP_USER_DATA"); - if (tmp != NULL) - return g_build_filename(tmp, FWUPD_LOCALSTATEDIR, NULL); - return g_build_filename(FWUPD_LOCALSTATEDIR, NULL); -#endif - /* /proc */ - case FU_PATH_KIND_PROCFS: - tmp = g_getenv("FWUPD_PROCFS"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/proc"); - /* /sys/firmware */ - case FU_PATH_KIND_SYSFSDIR_FW: - tmp = g_getenv("FWUPD_SYSFSFWDIR"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/firmware"); - /* /sys/class/tpm */ - case FU_PATH_KIND_SYSFSDIR_TPM: - tmp = g_getenv("FWUPD_SYSFSTPMDIR"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/class/tpm"); - /* /sys/bus/platform/drivers */ - case FU_PATH_KIND_SYSFSDIR_DRIVERS: - tmp = g_getenv("FWUPD_SYSFSDRIVERDIR"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/bus/platform/drivers"); - /* /sys/kernel/security */ - case FU_PATH_KIND_SYSFSDIR_SECURITY: - tmp = g_getenv("FWUPD_SYSFSSECURITYDIR"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/kernel/security"); - /* /sys/firmware/acpi/tables */ - case FU_PATH_KIND_ACPI_TABLES: - tmp = g_getenv("FWUPD_ACPITABLESDIR"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/firmware/acpi/tables"); - /* /sys/module/firmware_class/parameters/path */ - case FU_PATH_KIND_FIRMWARE_SEARCH: - tmp = g_getenv("FWUPD_FIRMWARESEARCH"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/module/firmware_class/parameters/path"); - /* /etc */ - case FU_PATH_KIND_SYSCONFDIR: - tmp = g_getenv("FWUPD_SYSCONFDIR"); - if (tmp != NULL) - return g_strdup(tmp); - tmp = g_getenv("SNAP_USER_DATA"); - if (tmp != NULL) - return g_build_filename(tmp, FWUPD_SYSCONFDIR, NULL); - basedir = fu_common_get_win32_basedir(); - if (basedir != NULL) - return g_build_filename(basedir, FWUPD_SYSCONFDIR, NULL); - return g_strdup(FWUPD_SYSCONFDIR); - - /* /usr/lib//fwupd-plugins-3 */ - case FU_PATH_KIND_PLUGINDIR_PKG: - tmp = g_getenv("FWUPD_PLUGINDIR"); - if (tmp != NULL) - return g_strdup(tmp); - tmp = g_getenv("SNAP"); - if (tmp != NULL) - return g_build_filename(tmp, FWUPD_PLUGINDIR, NULL); - basedir = fu_common_get_win32_basedir(); - if (basedir != NULL) - return g_build_filename(basedir, FWUPD_PLUGINDIR, NULL); - return g_build_filename(FWUPD_PLUGINDIR, NULL); - /* /usr/share/fwupd */ - case FU_PATH_KIND_DATADIR_PKG: - tmp = g_getenv("FWUPD_DATADIR"); - if (tmp != NULL) - return g_strdup(tmp); - tmp = g_getenv("SNAP"); - if (tmp != NULL) - return g_build_filename(tmp, FWUPD_DATADIR, PACKAGE_NAME, NULL); - basedir = fu_common_get_win32_basedir(); - if (basedir != NULL) - return g_build_filename(basedir, FWUPD_DATADIR, PACKAGE_NAME, NULL); - return g_build_filename(FWUPD_DATADIR, PACKAGE_NAME, NULL); - /* /usr/share/fwupd/quirks.d */ - case FU_PATH_KIND_DATADIR_QUIRKS: - tmp = g_getenv("FWUPD_DATADIR_QUIRKS"); - if (tmp != NULL) - return g_strdup(tmp); - basedir = fu_common_get_path(FU_PATH_KIND_DATADIR_PKG); - return g_build_filename(basedir, "quirks.d", NULL); - /* /usr/libexec/fwupd/efi */ - case FU_PATH_KIND_EFIAPPDIR: - tmp = g_getenv("FWUPD_EFIAPPDIR"); - if (tmp != NULL) - return g_strdup(tmp); -#ifdef EFI_APP_LOCATION - tmp = g_getenv("SNAP"); - if (tmp != NULL) - return g_build_filename(tmp, EFI_APP_LOCATION, NULL); - return g_strdup(EFI_APP_LOCATION); -#else - return NULL; -#endif - /* /etc/fwupd */ - case FU_PATH_KIND_SYSCONFDIR_PKG: - tmp = g_getenv("CONFIGURATION_DIRECTORY"); - if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR); - return g_build_filename(basedir, PACKAGE_NAME, NULL); - /* /var/lib/fwupd */ - case FU_PATH_KIND_LOCALSTATEDIR_PKG: - tmp = g_getenv("STATE_DIRECTORY"); - if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR); - return g_build_filename(basedir, "lib", PACKAGE_NAME, NULL); - /* /var/lib/fwupd/quirks.d */ - case FU_PATH_KIND_LOCALSTATEDIR_QUIRKS: - tmp = g_getenv("FWUPD_LOCALSTATEDIR_QUIRKS"); - if (tmp != NULL) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); - return g_build_filename(basedir, "quirks.d", NULL); - /* /var/lib/fwupd/metadata */ - case FU_PATH_KIND_LOCALSTATEDIR_METADATA: - tmp = g_getenv("FWUPD_LOCALSTATEDIR_METADATA"); - if (tmp != NULL) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); - return g_build_filename(basedir, "metadata", NULL); - /* /var/lib/fwupd/remotes.d */ - case FU_PATH_KIND_LOCALSTATEDIR_REMOTES: - tmp = g_getenv("FWUPD_LOCALSTATEDIR_REMOTES"); - if (tmp != NULL) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); - return g_build_filename(basedir, "remotes.d", NULL); - /* /var/cache/fwupd */ - case FU_PATH_KIND_CACHEDIR_PKG: - tmp = g_getenv("CACHE_DIRECTORY"); - if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR); - return g_build_filename(basedir, "cache", PACKAGE_NAME, NULL); - /* /var/etc/fwupd */ - case FU_PATH_KIND_LOCALCONFDIR_PKG: - tmp = g_getenv("LOCALCONF_DIRECTORY"); - if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) - return g_build_filename(tmp, NULL); - basedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR); - return g_build_filename(basedir, "etc", PACKAGE_NAME, NULL); - /* /run/lock */ - case FU_PATH_KIND_LOCKDIR: - return g_strdup("/run/lock"); - /* /sys/class/firmware-attributes */ - case FU_PATH_KIND_SYSFSDIR_FW_ATTRIB: - tmp = g_getenv("FWUPD_SYSFSFWATTRIBDIR"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/sys/class/firmware-attributes"); - case FU_PATH_KIND_OFFLINE_TRIGGER: - tmp = g_getenv("FWUPD_OFFLINE_TRIGGER"); - if (tmp != NULL) - return g_strdup(tmp); - return g_strdup("/system-update"); - case FU_PATH_KIND_POLKIT_ACTIONS: -#ifdef POLKIT_ACTIONDIR - return g_strdup(POLKIT_ACTIONDIR); -#else - return NULL; -#endif - /* C:\Program Files (x86)\fwupd\ */ - case FU_PATH_KIND_WIN32_BASEDIR: - return fu_common_get_win32_basedir(); - /* this shouldn't happen */ - default: - g_warning("cannot build path for unknown kind %u", path_kind); - } - - return NULL; -} - -/** - * fu_common_fnmatch: - * @pattern: a glob pattern, e.g. `*foo*` - * @str: a string to match against the pattern, e.g. `bazfoobar` - * - * Matches a string against a glob pattern. - * - * Returns: %TRUE if the string matched - * - * Since: 1.3.5 - **/ -gboolean -fu_common_fnmatch(const gchar *pattern, const gchar *str) -{ - g_return_val_if_fail(pattern != NULL, FALSE); - g_return_val_if_fail(str != NULL, FALSE); - return fu_common_fnmatch_impl(pattern, str); -} - -static gint -fu_common_filename_glob_sort_cb(gconstpointer a, gconstpointer b) -{ - return g_strcmp0(*(const gchar **)a, *(const gchar **)b); -} - -/** - * fu_common_filename_glob: - * @directory: a directory path - * @pattern: a glob pattern, e.g. `*foo*` - * @error: (nullable): optional return location for an error - * - * Returns all the filenames that match a specific glob pattern. - * Any results are sorted. No matching files will set @error. - * - * Returns: (element-type utf8) (transfer container): matching files, or %NULL - * - * Since: 1.5.0 - **/ -GPtrArray * -fu_common_filename_glob(const gchar *directory, const gchar *pattern, GError **error) -{ - const gchar *basename; - g_autoptr(GDir) dir = NULL; - g_autoptr(GPtrArray) files = g_ptr_array_new_with_free_func(g_free); - - g_return_val_if_fail(directory != NULL, NULL); - g_return_val_if_fail(pattern != NULL, NULL); - g_return_val_if_fail(error == NULL || *error == NULL, NULL); - - dir = g_dir_open(directory, 0, error); - if (dir == NULL) - return NULL; - while ((basename = g_dir_read_name(dir)) != NULL) { - if (!fu_common_fnmatch(pattern, basename)) - continue; - g_ptr_array_add(files, g_build_filename(directory, basename, NULL)); - } - if (files->len == 0) { - g_set_error_literal(error, - G_IO_ERROR, - G_IO_ERROR_NOT_FOUND, - "no files matched pattern"); - return NULL; - } - g_ptr_array_sort(files, fu_common_filename_glob_sort_cb); - return g_steal_pointer(&files); -} - /** * fu_common_cpuid: * @leaf: the CPUID level, now called the 'leaf' by Intel diff --git a/libfwupdplugin/fu-common.h b/libfwupdplugin/fu-common.h index a247832b3..c546d2ae9 100644 --- a/libfwupdplugin/fu-common.h +++ b/libfwupdplugin/fu-common.h @@ -18,75 +18,6 @@ **/ typedef guint FuEndianType; -/** - * FuPathKind: - * @FU_PATH_KIND_CACHEDIR_PKG: The cache directory (IE /var/cache/fwupd) - * @FU_PATH_KIND_DATADIR_PKG: The non-volatile data store (IE /usr/share/fwupd) - * @FU_PATH_KIND_EFIAPPDIR: The location to store EFI apps before install (IE - * /usr/libexec/fwupd/efi) - * @FU_PATH_KIND_LOCALSTATEDIR: The local state directory (IE /var) - * @FU_PATH_KIND_LOCALSTATEDIR_PKG: The local state directory for the package (IE - * /var/lib/fwupd) - * @FU_PATH_KIND_PLUGINDIR_PKG: The location to look for plugins for package (IE - * /usr/lib/[triplet]/fwupd-plugins-3) - * @FU_PATH_KIND_SYSCONFDIR: The configuration location (IE /etc) - * @FU_PATH_KIND_SYSCONFDIR_PKG: The package configuration location (IE /etc/fwupd) - * @FU_PATH_KIND_SYSFSDIR_FW: The sysfs firmware location (IE /sys/firmware) - * @FU_PATH_KIND_SYSFSDIR_DRIVERS: The platform sysfs directory (IE /sys/bus/platform/drivers) - * @FU_PATH_KIND_SYSFSDIR_TPM: The TPM sysfs directory (IE /sys/class/tpm) - * @FU_PATH_KIND_PROCFS: The procfs location (IE /proc) - * @FU_PATH_KIND_POLKIT_ACTIONS: The directory for policy kit actions (IE - * /usr/share/polkit-1/actions/) - * @FU_PATH_KIND_OFFLINE_TRIGGER: The file for the offline trigger (IE /system-update) - * @FU_PATH_KIND_SYSFSDIR_SECURITY: The sysfs security location (IE /sys/kernel/security) - * @FU_PATH_KIND_ACPI_TABLES: The location of the ACPI tables - * @FU_PATH_KIND_LOCKDIR: The lock directory (IE /run/lock) - * @FU_PATH_KIND_SYSFSDIR_FW_ATTRIB The firmware attributes directory (IE - * /sys/class/firmware-attributes) - * @FU_PATH_KIND_FIRMWARE_SEARCH: The path to configure the kernel policy for runtime loading - *other than /lib/firmware (IE /sys/module/firmware_class/parameters/path) - * @FU_PATH_KIND_DATADIR_QUIRKS: The quirks data store (IE /usr/share/fwupd/quirks.d) - * @FU_PATH_KIND_LOCALSTATEDIR_QUIRKS: The local state directory for quirks (IE - * /var/lib/fwupd/quirks.d) - * @FU_PATH_KIND_LOCALSTATEDIR_METADATA: The local state directory for metadata (IE - * /var/lib/fwupd/metadata) - * @FU_PATH_KIND_LOCALSTATEDIR_REMOTES: The local state directory for remotes (IE - * /var/lib/fwupd/remotes.d) - * @FU_PATH_KIND_WIN32_BASEDIR: The root of the install directory on Windows - * @FU_PATH_KIND_LOCALCONFDIR_PKG: The package configuration override (IE /var/etc/fwupd) - * - * Path types to use when dynamically determining a path at runtime - **/ -typedef enum { - FU_PATH_KIND_CACHEDIR_PKG, - FU_PATH_KIND_DATADIR_PKG, - FU_PATH_KIND_EFIAPPDIR, - FU_PATH_KIND_LOCALSTATEDIR, - FU_PATH_KIND_LOCALSTATEDIR_PKG, - FU_PATH_KIND_PLUGINDIR_PKG, - FU_PATH_KIND_SYSCONFDIR, - FU_PATH_KIND_SYSCONFDIR_PKG, - FU_PATH_KIND_SYSFSDIR_FW, - FU_PATH_KIND_SYSFSDIR_DRIVERS, - FU_PATH_KIND_SYSFSDIR_TPM, - FU_PATH_KIND_PROCFS, - FU_PATH_KIND_POLKIT_ACTIONS, - FU_PATH_KIND_OFFLINE_TRIGGER, - FU_PATH_KIND_SYSFSDIR_SECURITY, - FU_PATH_KIND_ACPI_TABLES, - FU_PATH_KIND_LOCKDIR, - FU_PATH_KIND_SYSFSDIR_FW_ATTRIB, - FU_PATH_KIND_FIRMWARE_SEARCH, - FU_PATH_KIND_DATADIR_QUIRKS, - FU_PATH_KIND_LOCALSTATEDIR_QUIRKS, - FU_PATH_KIND_LOCALSTATEDIR_METADATA, - FU_PATH_KIND_LOCALSTATEDIR_REMOTES, - FU_PATH_KIND_WIN32_BASEDIR, - FU_PATH_KIND_LOCALCONFDIR_PKG, - /*< private >*/ - FU_PATH_KIND_LAST -} FuPathKind; - /** * FuCpuVendor: * @FU_CPU_VENDOR_UNKNOWN: Unknown @@ -139,24 +70,6 @@ typedef enum { FU_LID_STATE_LAST } FuLidState; -gchar * -fu_common_get_path(FuPathKind path_kind); -GPtrArray * -fu_common_filename_glob(const gchar *directory, - const gchar *pattern, - GError **error) G_GNUC_WARN_UNUSED_RESULT; -gboolean -fu_common_fnmatch(const gchar *pattern, const gchar *str); -gboolean -fu_common_rmtree(const gchar *directory, GError **error) G_GNUC_WARN_UNUSED_RESULT; -GPtrArray * -fu_common_get_files_recursive(const gchar *path, GError **error) G_GNUC_WARN_UNUSED_RESULT; -gboolean -fu_common_mkdir(const gchar *dirname, GError **error) G_GNUC_WARN_UNUSED_RESULT; -gboolean -fu_common_mkdir_parent(const gchar *filename, GError **error) G_GNUC_WARN_UNUSED_RESULT; -gchar * -fu_common_find_program_in_path(const gchar *basename, GError **error) G_GNUC_WARN_UNUSED_RESULT; gboolean fu_common_cpuid(guint32 leaf, guint32 *eax, diff --git a/libfwupdplugin/fu-efivar-freebsd.c b/libfwupdplugin/fu-efivar-freebsd.c index 01b31dc02..fe91fee0e 100644 --- a/libfwupdplugin/fu-efivar-freebsd.c +++ b/libfwupdplugin/fu-efivar-freebsd.c @@ -15,6 +15,7 @@ #include "fu-common.h" #include "fu-efivar-impl.h" +#include "fu-path.h" gboolean fu_efivar_supported_impl(GError **error) @@ -55,7 +56,7 @@ fu_efivar_delete_with_glob_impl(const gchar *guid, const gchar *name_glob, GErro while (efi_get_next_variable_name(&guidt, &name)) { if (memcmp(&guid_to_delete, guidt, sizeof(guid_to_delete)) != 0) continue; - if (!fu_common_fnmatch(name, name_glob)) + if (!fu_path_fnmatch(name, name_glob)) continue; rv = fu_efivar_delete(guid, name, error); if (!rv) diff --git a/libfwupdplugin/fu-efivar-linux.c b/libfwupdplugin/fu-efivar-linux.c index cccf78847..83bfaf1f2 100644 --- a/libfwupdplugin/fu-efivar-linux.c +++ b/libfwupdplugin/fu-efivar-linux.c @@ -19,11 +19,12 @@ #include "fu-common.h" #include "fu-efivar-impl.h" +#include "fu-path.h" static gchar * fu_efivar_get_path(void) { - g_autofree gchar *sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + g_autofree gchar *sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); return g_build_filename(sysfsfwdir, "efi", "efivars", NULL); } @@ -159,7 +160,7 @@ fu_efivar_delete_with_glob_impl(const gchar *guid, const gchar *name_glob, GErro return FALSE; nameguid_glob = g_strdup_printf("%s-%s", name_glob, guid); while ((fn = g_dir_read_name(dir)) != NULL) { - if (fu_common_fnmatch(nameguid_glob, fn)) { + if (fu_path_fnmatch(nameguid_glob, fn)) { g_autofree gchar *keyfn = g_build_filename(efivardir, fn, NULL); g_autoptr(GFile) file = g_file_new_for_path(keyfn); if (!fu_efivar_set_immutable(keyfn, FALSE, NULL, error)) { diff --git a/libfwupdplugin/fu-hwids.c b/libfwupdplugin/fu-hwids.c index 9ed797d81..7a02f994f 100644 --- a/libfwupdplugin/fu-hwids.c +++ b/libfwupdplugin/fu-hwids.c @@ -17,6 +17,7 @@ #include "fu-common.h" #include "fu-hwids.h" +#include "fu-path.h" #include "fu-string.h" /** @@ -355,8 +356,8 @@ fu_hwids_convert_integer_cb(FuSmbios *smbios, guint8 type, guint8 offset, GError static gboolean fu_hwids_setup_overrides(FuHwids *self, GError **error) { - g_autofree gchar *localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); - g_autofree gchar *sysconfigdir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR_PKG); + g_autofree gchar *localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); + g_autofree gchar *sysconfigdir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR_PKG); g_autoptr(GKeyFile) kf = g_key_file_new(); g_autoptr(GPtrArray) fns = g_ptr_array_new_with_free_func(g_free); g_autoptr(GPtrArray) keys = fu_hwids_get_keys(self); diff --git a/libfwupdplugin/fu-kernel.c b/libfwupdplugin/fu-kernel.c index 85c89a4e3..d954d0bbb 100644 --- a/libfwupdplugin/fu-kernel.c +++ b/libfwupdplugin/fu-kernel.c @@ -17,6 +17,7 @@ #include "fu-common-version.h" #include "fu-common.h" #include "fu-kernel.h" +#include "fu-path.h" /** * fu_kernel_locked_down: @@ -30,7 +31,7 @@ fu_kernel_locked_down(void) { #ifdef __linux__ gsize len = 0; - g_autofree gchar *dir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_SECURITY); + g_autofree gchar *dir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_SECURITY); g_autofree gchar *fname = g_build_filename(dir, "lockdown", NULL); g_autofree gchar *data = NULL; g_auto(GStrv) options = NULL; @@ -117,7 +118,7 @@ fu_kernel_get_firmware_search_path(GError **error) g_autofree gchar *sys_fw_search_path = NULL; g_autofree gchar *contents = NULL; - sys_fw_search_path = fu_common_get_path(FU_PATH_KIND_FIRMWARE_SEARCH); + sys_fw_search_path = fu_path_from_kind(FU_PATH_KIND_FIRMWARE_SEARCH); if (!g_file_get_contents(sys_fw_search_path, &contents, &sz, error)) return NULL; @@ -150,7 +151,7 @@ fu_kernel_set_firmware_search_path(const gchar *path, GError **error) g_return_val_if_fail(path != NULL, FALSE); g_return_val_if_fail(strlen(path) < PATH_MAX, FALSE); - sys_fw_search_path_prm = fu_common_get_path(FU_PATH_KIND_FIRMWARE_SEARCH); + sys_fw_search_path_prm = fu_path_from_kind(FU_PATH_KIND_FIRMWARE_SEARCH); g_debug("writing firmware search path (%" G_GSIZE_FORMAT "): %s", strlen(path), path); @@ -168,7 +169,7 @@ fu_kernel_set_firmware_search_path(const gchar *path, GError **error) g_return_val_if_fail(path != NULL, FALSE); g_return_val_if_fail(strlen(path) < PATH_MAX, FALSE); - sys_fw_search_path_prm = fu_common_get_path(FU_PATH_KIND_FIRMWARE_SEARCH); + sys_fw_search_path_prm = fu_path_from_kind(FU_PATH_KIND_FIRMWARE_SEARCH); /* g_file_set_contents will try to create backup files in sysfs, so use fopen here */ fd = fopen(sys_fw_search_path_prm, "w"); if (fd == NULL) { diff --git a/libfwupdplugin/fu-path-private.h b/libfwupdplugin/fu-path-private.h new file mode 100644 index 000000000..270cba966 --- /dev/null +++ b/libfwupdplugin/fu-path-private.h @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2021 Richard Hughes + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include "fu-path.h" + +gboolean +fu_path_fnmatch_impl(const gchar *pattern, const gchar *str); diff --git a/libfwupdplugin/fu-path.c b/libfwupdplugin/fu-path.c new file mode 100644 index 000000000..16d221f69 --- /dev/null +++ b/libfwupdplugin/fu-path.c @@ -0,0 +1,508 @@ +/* + * Copyright (C) 2017 Richard Hughes + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#define G_LOG_DOMAIN "FuCommon" + +#include "config.h" + +#include +#include + +#ifdef _WIN32 +#include +#endif + +#include "fwupd-error.h" + +#include "fu-path-private.h" + +/** + * fu_path_rmtree: + * @directory: a directory name + * @error: (nullable): optional return location for an error + * + * Recursively removes a directory. + * + * Returns: %TRUE for success, %FALSE otherwise + * + * Since: 1.8.2 + **/ +gboolean +fu_path_rmtree(const gchar *directory, GError **error) +{ + const gchar *filename; + g_autoptr(GDir) dir = NULL; + + g_return_val_if_fail(directory != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* try to open */ + g_debug("removing %s", directory); + dir = g_dir_open(directory, 0, error); + if (dir == NULL) + return FALSE; + + /* find each */ + while ((filename = g_dir_read_name(dir))) { + g_autofree gchar *src = NULL; + src = g_build_filename(directory, filename, NULL); + if (g_file_test(src, G_FILE_TEST_IS_DIR)) { + if (!fu_path_rmtree(src, error)) + return FALSE; + } else { + if (g_unlink(src) != 0) { + g_set_error(error, + FWUPD_ERROR, + FWUPD_ERROR_INTERNAL, + "Failed to delete: %s", + src); + return FALSE; + } + } + } + if (g_remove(directory) != 0) { + g_set_error(error, + FWUPD_ERROR, + FWUPD_ERROR_INTERNAL, + "Failed to delete: %s", + directory); + return FALSE; + } + return TRUE; +} + +static gboolean +fu_path_get_file_list_internal(GPtrArray *files, const gchar *directory, GError **error) +{ + const gchar *filename; + g_autoptr(GDir) dir = NULL; + + /* try to open */ + dir = g_dir_open(directory, 0, error); + if (dir == NULL) + return FALSE; + + /* find each */ + while ((filename = g_dir_read_name(dir))) { + g_autofree gchar *src = g_build_filename(directory, filename, NULL); + if (g_file_test(src, G_FILE_TEST_IS_DIR)) { + if (!fu_path_get_file_list_internal(files, src, error)) + return FALSE; + } else { + g_ptr_array_add(files, g_steal_pointer(&src)); + } + } + return TRUE; +} + +/** + * fu_path_get_files: + * @path: a directory name + * @error: (nullable): optional return location for an error + * + * Returns every file found under @directory, and any subdirectory. + * If any path under @directory cannot be accessed due to permissions an error + * will be returned. + * + * Returns: (transfer container) (element-type utf8): array of files, or %NULL for error + * + * Since: 1.8.2 + **/ +GPtrArray * +fu_path_get_files(const gchar *path, GError **error) +{ + g_autoptr(GPtrArray) files = g_ptr_array_new_with_free_func(g_free); + + g_return_val_if_fail(path != NULL, NULL); + g_return_val_if_fail(error == NULL || *error == NULL, NULL); + + if (!fu_path_get_file_list_internal(files, path, error)) + return NULL; + return g_steal_pointer(&files); +} + +/** + * fu_path_mkdir: + * @dirname: a directory name + * @error: (nullable): optional return location for an error + * + * Creates any required directories, including any parent directories. + * + * Returns: %TRUE for success + * + * Since: 1.8.2 + **/ +gboolean +fu_path_mkdir(const gchar *dirname, GError **error) +{ + g_return_val_if_fail(dirname != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) + g_debug("creating path %s", dirname); + if (g_mkdir_with_parents(dirname, 0755) == -1) { + g_set_error(error, + FWUPD_ERROR, + FWUPD_ERROR_INTERNAL, + "Failed to create '%s': %s", + dirname, + g_strerror(errno)); + return FALSE; + } + return TRUE; +} + +/** + * fu_path_mkdir_parent: + * @filename: a full pathname + * @error: (nullable): optional return location for an error + * + * Creates any required directories, including any parent directories. + * + * Returns: %TRUE for success + * + * Since: 1.8.2 + **/ +gboolean +fu_path_mkdir_parent(const gchar *filename, GError **error) +{ + g_autofree gchar *parent = NULL; + + g_return_val_if_fail(filename != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + parent = g_path_get_dirname(filename); + return fu_path_mkdir(parent, error); +} + +/** + * fu_path_find_program: + * @basename: the program to search + * @error: (nullable): optional return location for an error + * + * Looks for a program in the PATH variable + * + * Returns: a new #gchar, or %NULL for error + * + * Since: 1.8.2 + **/ +gchar * +fu_path_find_program(const gchar *basename, GError **error) +{ + gchar *fn = g_find_program_in_path(basename); + if (fn == NULL) { + g_set_error(error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "missing executable %s in PATH", + basename); + return NULL; + } + return fn; +} + +/** + * fu_path_get_win32_basedir: + * + * Gets the base directory that fwupd has been launched from on Windows. + * This is the directory containing all subdirectories (IE 'C:\Program Files (x86)\fwupd\') + * + * Returns: The system path, or %NULL if invalid + * + * Since: 1.8.2 + **/ +static gchar * +fu_path_get_win32_basedir(void) +{ +#ifdef _WIN32 + char drive_buf[_MAX_DRIVE]; + char dir_buf[_MAX_DIR]; + _splitpath(_pgmptr, drive_buf, dir_buf, NULL, NULL); + return g_build_filename(drive_buf, dir_buf, "..", NULL); +#endif + return NULL; +} + +/** + * fu_path_from_kind: + * @path_kind: a #FuPathKind e.g. %FU_PATH_KIND_DATADIR_PKG + * + * Gets a fwupd-specific system path. These can be overridden with various + * environment variables, for instance %FWUPD_DATADIR. + * + * Returns: a system path, or %NULL if invalid + * + * Since: 1.8.2 + **/ +gchar * +fu_path_from_kind(FuPathKind path_kind) +{ + const gchar *tmp; + g_autofree gchar *basedir = NULL; + + switch (path_kind) { + /* /var */ + case FU_PATH_KIND_LOCALSTATEDIR: + tmp = g_getenv("FWUPD_LOCALSTATEDIR"); + if (tmp != NULL) + return g_strdup(tmp); +#ifdef _WIN32 + return g_build_filename(g_getenv("USERPROFILE"), + PACKAGE_NAME, + FWUPD_LOCALSTATEDIR, + NULL); +#else + tmp = g_getenv("SNAP_USER_DATA"); + if (tmp != NULL) + return g_build_filename(tmp, FWUPD_LOCALSTATEDIR, NULL); + return g_build_filename(FWUPD_LOCALSTATEDIR, NULL); +#endif + /* /proc */ + case FU_PATH_KIND_PROCFS: + tmp = g_getenv("FWUPD_PROCFS"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/proc"); + /* /sys/firmware */ + case FU_PATH_KIND_SYSFSDIR_FW: + tmp = g_getenv("FWUPD_SYSFSFWDIR"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/firmware"); + /* /sys/class/tpm */ + case FU_PATH_KIND_SYSFSDIR_TPM: + tmp = g_getenv("FWUPD_SYSFSTPMDIR"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/class/tpm"); + /* /sys/bus/platform/drivers */ + case FU_PATH_KIND_SYSFSDIR_DRIVERS: + tmp = g_getenv("FWUPD_SYSFSDRIVERDIR"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/bus/platform/drivers"); + /* /sys/kernel/security */ + case FU_PATH_KIND_SYSFSDIR_SECURITY: + tmp = g_getenv("FWUPD_SYSFSSECURITYDIR"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/kernel/security"); + /* /sys/firmware/acpi/tables */ + case FU_PATH_KIND_ACPI_TABLES: + tmp = g_getenv("FWUPD_ACPITABLESDIR"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/firmware/acpi/tables"); + /* /sys/module/firmware_class/parameters/path */ + case FU_PATH_KIND_FIRMWARE_SEARCH: + tmp = g_getenv("FWUPD_FIRMWARESEARCH"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/module/firmware_class/parameters/path"); + /* /etc */ + case FU_PATH_KIND_SYSCONFDIR: + tmp = g_getenv("FWUPD_SYSCONFDIR"); + if (tmp != NULL) + return g_strdup(tmp); + tmp = g_getenv("SNAP_USER_DATA"); + if (tmp != NULL) + return g_build_filename(tmp, FWUPD_SYSCONFDIR, NULL); + basedir = fu_path_get_win32_basedir(); + if (basedir != NULL) + return g_build_filename(basedir, FWUPD_SYSCONFDIR, NULL); + return g_strdup(FWUPD_SYSCONFDIR); + + /* /usr/lib//fwupd-plugins-3 */ + case FU_PATH_KIND_PLUGINDIR_PKG: + tmp = g_getenv("FWUPD_PLUGINDIR"); + if (tmp != NULL) + return g_strdup(tmp); + tmp = g_getenv("SNAP"); + if (tmp != NULL) + return g_build_filename(tmp, FWUPD_PLUGINDIR, NULL); + basedir = fu_path_get_win32_basedir(); + if (basedir != NULL) + return g_build_filename(basedir, FWUPD_PLUGINDIR, NULL); + return g_build_filename(FWUPD_PLUGINDIR, NULL); + /* /usr/share/fwupd */ + case FU_PATH_KIND_DATADIR_PKG: + tmp = g_getenv("FWUPD_DATADIR"); + if (tmp != NULL) + return g_strdup(tmp); + tmp = g_getenv("SNAP"); + if (tmp != NULL) + return g_build_filename(tmp, FWUPD_DATADIR, PACKAGE_NAME, NULL); + basedir = fu_path_get_win32_basedir(); + if (basedir != NULL) + return g_build_filename(basedir, FWUPD_DATADIR, PACKAGE_NAME, NULL); + return g_build_filename(FWUPD_DATADIR, PACKAGE_NAME, NULL); + /* /usr/share/fwupd/quirks.d */ + case FU_PATH_KIND_DATADIR_QUIRKS: + tmp = g_getenv("FWUPD_DATADIR_QUIRKS"); + if (tmp != NULL) + return g_strdup(tmp); + basedir = fu_path_from_kind(FU_PATH_KIND_DATADIR_PKG); + return g_build_filename(basedir, "quirks.d", NULL); + /* /usr/libexec/fwupd/efi */ + case FU_PATH_KIND_EFIAPPDIR: + tmp = g_getenv("FWUPD_EFIAPPDIR"); + if (tmp != NULL) + return g_strdup(tmp); +#ifdef EFI_APP_LOCATION + tmp = g_getenv("SNAP"); + if (tmp != NULL) + return g_build_filename(tmp, EFI_APP_LOCATION, NULL); + return g_strdup(EFI_APP_LOCATION); +#else + return NULL; +#endif + /* /etc/fwupd */ + case FU_PATH_KIND_SYSCONFDIR_PKG: + tmp = g_getenv("CONFIGURATION_DIRECTORY"); + if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR); + return g_build_filename(basedir, PACKAGE_NAME, NULL); + /* /var/lib/fwupd */ + case FU_PATH_KIND_LOCALSTATEDIR_PKG: + tmp = g_getenv("STATE_DIRECTORY"); + if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR); + return g_build_filename(basedir, "lib", PACKAGE_NAME, NULL); + /* /var/lib/fwupd/quirks.d */ + case FU_PATH_KIND_LOCALSTATEDIR_QUIRKS: + tmp = g_getenv("FWUPD_LOCALSTATEDIR_QUIRKS"); + if (tmp != NULL) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); + return g_build_filename(basedir, "quirks.d", NULL); + /* /var/lib/fwupd/metadata */ + case FU_PATH_KIND_LOCALSTATEDIR_METADATA: + tmp = g_getenv("FWUPD_LOCALSTATEDIR_METADATA"); + if (tmp != NULL) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); + return g_build_filename(basedir, "metadata", NULL); + /* /var/lib/fwupd/remotes.d */ + case FU_PATH_KIND_LOCALSTATEDIR_REMOTES: + tmp = g_getenv("FWUPD_LOCALSTATEDIR_REMOTES"); + if (tmp != NULL) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); + return g_build_filename(basedir, "remotes.d", NULL); + /* /var/cache/fwupd */ + case FU_PATH_KIND_CACHEDIR_PKG: + tmp = g_getenv("CACHE_DIRECTORY"); + if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR); + return g_build_filename(basedir, "cache", PACKAGE_NAME, NULL); + /* /var/etc/fwupd */ + case FU_PATH_KIND_LOCALCONFDIR_PKG: + tmp = g_getenv("LOCALCONF_DIRECTORY"); + if (tmp != NULL && g_file_test(tmp, G_FILE_TEST_EXISTS)) + return g_build_filename(tmp, NULL); + basedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR); + return g_build_filename(basedir, "etc", PACKAGE_NAME, NULL); + /* /run/lock */ + case FU_PATH_KIND_LOCKDIR: + return g_strdup("/run/lock"); + /* /sys/class/firmware-attributes */ + case FU_PATH_KIND_SYSFSDIR_FW_ATTRIB: + tmp = g_getenv("FWUPD_SYSFSFWATTRIBDIR"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/sys/class/firmware-attributes"); + case FU_PATH_KIND_OFFLINE_TRIGGER: + tmp = g_getenv("FWUPD_OFFLINE_TRIGGER"); + if (tmp != NULL) + return g_strdup(tmp); + return g_strdup("/system-update"); + case FU_PATH_KIND_POLKIT_ACTIONS: +#ifdef POLKIT_ACTIONDIR + return g_strdup(POLKIT_ACTIONDIR); +#else + return NULL; +#endif + /* C:\Program Files (x86)\fwupd\ */ + case FU_PATH_KIND_WIN32_BASEDIR: + return fu_path_get_win32_basedir(); + /* this shouldn't happen */ + default: + g_warning("cannot build path for unknown kind %u", path_kind); + } + + return NULL; +} + +/** + * fu_path_fnmatch: + * @pattern: a glob pattern, e.g. `*foo*` + * @str: a string to match against the pattern, e.g. `bazfoobar` + * + * Matches a string against a glob pattern. + * + * Returns: %TRUE if the string matched + * + * Since: 1.8.2 + **/ +gboolean +fu_path_fnmatch(const gchar *pattern, const gchar *str) +{ + g_return_val_if_fail(pattern != NULL, FALSE); + g_return_val_if_fail(str != NULL, FALSE); + return fu_path_fnmatch_impl(pattern, str); +} + +static gint +fu_path_glob_sort_cb(gconstpointer a, gconstpointer b) +{ + return g_strcmp0(*(const gchar **)a, *(const gchar **)b); +} + +/** + * fu_path_glob: + * @directory: a directory path + * @pattern: a glob pattern, e.g. `*foo*` + * @error: (nullable): optional return location for an error + * + * Returns all the filenames that match a specific glob pattern. + * Any results are sorted. No matching files will set @error. + * + * Returns: (element-type utf8) (transfer container): matching files, or %NULL + * + * Since: 1.8.2 + **/ +GPtrArray * +fu_path_glob(const gchar *directory, const gchar *pattern, GError **error) +{ + const gchar *basename; + g_autoptr(GDir) dir = NULL; + g_autoptr(GPtrArray) files = g_ptr_array_new_with_free_func(g_free); + + g_return_val_if_fail(directory != NULL, NULL); + g_return_val_if_fail(pattern != NULL, NULL); + g_return_val_if_fail(error == NULL || *error == NULL, NULL); + + dir = g_dir_open(directory, 0, error); + if (dir == NULL) + return NULL; + while ((basename = g_dir_read_name(dir)) != NULL) { + if (!fu_path_fnmatch(pattern, basename)) + continue; + g_ptr_array_add(files, g_build_filename(directory, basename, NULL)); + } + if (files->len == 0) { + g_set_error_literal(error, + G_IO_ERROR, + G_IO_ERROR_NOT_FOUND, + "no files matched pattern"); + return NULL; + } + g_ptr_array_sort(files, fu_path_glob_sort_cb); + return g_steal_pointer(&files); +} diff --git a/libfwupdplugin/fu-path.h b/libfwupdplugin/fu-path.h new file mode 100644 index 000000000..e6e7436a8 --- /dev/null +++ b/libfwupdplugin/fu-path.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 Richard Hughes + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include + +/** + * FuPathKind: + * @FU_PATH_KIND_CACHEDIR_PKG: The cache directory (IE /var/cache/fwupd) + * @FU_PATH_KIND_DATADIR_PKG: The non-volatile data store (IE /usr/share/fwupd) + * @FU_PATH_KIND_EFIAPPDIR: The location to store EFI apps before install (IE + * /usr/libexec/fwupd/efi) + * @FU_PATH_KIND_LOCALSTATEDIR: The local state directory (IE /var) + * @FU_PATH_KIND_LOCALSTATEDIR_PKG: The local state directory for the package (IE + * /var/lib/fwupd) + * @FU_PATH_KIND_PLUGINDIR_PKG: The location to look for plugins for package (IE + * /usr/lib/[triplet]/fwupd-plugins-3) + * @FU_PATH_KIND_SYSCONFDIR: The configuration location (IE /etc) + * @FU_PATH_KIND_SYSCONFDIR_PKG: The package configuration location (IE /etc/fwupd) + * @FU_PATH_KIND_SYSFSDIR_FW: The sysfs firmware location (IE /sys/firmware) + * @FU_PATH_KIND_SYSFSDIR_DRIVERS: The platform sysfs directory (IE /sys/bus/platform/drivers) + * @FU_PATH_KIND_SYSFSDIR_TPM: The TPM sysfs directory (IE /sys/class/tpm) + * @FU_PATH_KIND_PROCFS: The procfs location (IE /proc) + * @FU_PATH_KIND_POLKIT_ACTIONS: The directory for policy kit actions (IE + * /usr/share/polkit-1/actions/) + * @FU_PATH_KIND_OFFLINE_TRIGGER: The file for the offline trigger (IE /system-update) + * @FU_PATH_KIND_SYSFSDIR_SECURITY: The sysfs security location (IE /sys/kernel/security) + * @FU_PATH_KIND_ACPI_TABLES: The location of the ACPI tables + * @FU_PATH_KIND_LOCKDIR: The lock directory (IE /run/lock) + * @FU_PATH_KIND_SYSFSDIR_FW_ATTRIB The firmware attributes directory (IE + * /sys/class/firmware-attributes) + * @FU_PATH_KIND_FIRMWARE_SEARCH: The path to configure the kernel policy for runtime loading + *other than /lib/firmware (IE /sys/module/firmware_class/parameters/path) + * @FU_PATH_KIND_DATADIR_QUIRKS: The quirks data store (IE /usr/share/fwupd/quirks.d) + * @FU_PATH_KIND_LOCALSTATEDIR_QUIRKS: The local state directory for quirks (IE + * /var/lib/fwupd/quirks.d) + * @FU_PATH_KIND_LOCALSTATEDIR_METADATA: The local state directory for metadata (IE + * /var/lib/fwupd/metadata) + * @FU_PATH_KIND_LOCALSTATEDIR_REMOTES: The local state directory for remotes (IE + * /var/lib/fwupd/remotes.d) + * @FU_PATH_KIND_WIN32_BASEDIR: The root of the install directory on Windows + * @FU_PATH_KIND_LOCALCONFDIR_PKG: The package configuration override (IE /var/etc/fwupd) + * + * Path types to use when dynamically determining a path at runtime + **/ +typedef enum { + FU_PATH_KIND_CACHEDIR_PKG, + FU_PATH_KIND_DATADIR_PKG, + FU_PATH_KIND_EFIAPPDIR, + FU_PATH_KIND_LOCALSTATEDIR, + FU_PATH_KIND_LOCALSTATEDIR_PKG, + FU_PATH_KIND_PLUGINDIR_PKG, + FU_PATH_KIND_SYSCONFDIR, + FU_PATH_KIND_SYSCONFDIR_PKG, + FU_PATH_KIND_SYSFSDIR_FW, + FU_PATH_KIND_SYSFSDIR_DRIVERS, + FU_PATH_KIND_SYSFSDIR_TPM, + FU_PATH_KIND_PROCFS, + FU_PATH_KIND_POLKIT_ACTIONS, + FU_PATH_KIND_OFFLINE_TRIGGER, + FU_PATH_KIND_SYSFSDIR_SECURITY, + FU_PATH_KIND_ACPI_TABLES, + FU_PATH_KIND_LOCKDIR, + FU_PATH_KIND_SYSFSDIR_FW_ATTRIB, + FU_PATH_KIND_FIRMWARE_SEARCH, + FU_PATH_KIND_DATADIR_QUIRKS, + FU_PATH_KIND_LOCALSTATEDIR_QUIRKS, + FU_PATH_KIND_LOCALSTATEDIR_METADATA, + FU_PATH_KIND_LOCALSTATEDIR_REMOTES, + FU_PATH_KIND_WIN32_BASEDIR, + FU_PATH_KIND_LOCALCONFDIR_PKG, + /*< private >*/ + FU_PATH_KIND_LAST +} FuPathKind; + +gchar * +fu_path_from_kind(FuPathKind path_kind); +GPtrArray * +fu_path_glob(const gchar *directory, + const gchar *pattern, + GError **error) G_GNUC_WARN_UNUSED_RESULT; +gboolean +fu_path_fnmatch(const gchar *pattern, const gchar *str); +gboolean +fu_path_rmtree(const gchar *directory, GError **error) G_GNUC_WARN_UNUSED_RESULT; +GPtrArray * +fu_path_get_files(const gchar *path, GError **error) G_GNUC_WARN_UNUSED_RESULT; +gboolean +fu_path_mkdir(const gchar *dirname, GError **error) G_GNUC_WARN_UNUSED_RESULT; +gboolean +fu_path_mkdir_parent(const gchar *filename, GError **error) G_GNUC_WARN_UNUSED_RESULT; +gchar * +fu_path_find_program(const gchar *basename, GError **error) G_GNUC_WARN_UNUSED_RESULT; diff --git a/libfwupdplugin/fu-plugin.c b/libfwupdplugin/fu-plugin.c index e5487766a..55d302c91 100644 --- a/libfwupdplugin/fu-plugin.c +++ b/libfwupdplugin/fu-plugin.c @@ -20,6 +20,7 @@ #include "fu-device-private.h" #include "fu-kernel.h" #include "fu-mutex.h" +#include "fu-path.h" #include "fu-plugin-private.h" #include "fu-string.h" @@ -428,7 +429,7 @@ fu_plugin_config_monitor_changed_cb(GFileMonitor *monitor, static gchar * fu_plugin_get_config_filename(FuPlugin *self) { - g_autofree gchar *conf_dir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR_PKG); + g_autofree gchar *conf_dir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR_PKG); g_autofree gchar *conf_file = g_strdup_printf("%s.conf", fu_plugin_get_name(self)); return g_build_filename(conf_dir, conf_file, NULL); } @@ -682,7 +683,7 @@ fu_plugin_device_write_firmware(FuPlugin *self, g_prefix_error(error, "failed to backup old firmware: "); return FALSE; } - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); fn = g_strdup_printf("%s.bin", fu_device_get_version(device)); path = g_build_filename( localstatedir, diff --git a/libfwupdplugin/fu-quirks.c b/libfwupdplugin/fu-quirks.c index d6cfadc4e..2efd63003 100644 --- a/libfwupdplugin/fu-quirks.c +++ b/libfwupdplugin/fu-quirks.c @@ -19,6 +19,7 @@ #include "fu-common.h" #include "fu-mutex.h" +#include "fu-path.h" #include "fu-quirks.h" #include "fu-string.h" @@ -302,12 +303,12 @@ fu_quirks_check_silo(FuQuirks *self, GError **error) /* system datadir */ builder = xb_builder_new(); - datadir = fu_common_get_path(FU_PATH_KIND_DATADIR_QUIRKS); + datadir = fu_path_from_kind(FU_PATH_KIND_DATADIR_QUIRKS); if (!fu_quirks_add_quirks_for_path(self, builder, datadir, error)) return FALSE; /* something we can write when using Ostree */ - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_QUIRKS); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_QUIRKS); if (!fu_quirks_add_quirks_for_path(self, builder, localstatedir, error)) return FALSE; @@ -318,7 +319,7 @@ fu_quirks_check_silo(FuQuirks *self, GError **error) if (file == NULL) return FALSE; } else { - g_autofree gchar *cachedirpkg = fu_common_get_path(FU_PATH_KIND_CACHEDIR_PKG); + g_autofree gchar *cachedirpkg = fu_path_from_kind(FU_PATH_KIND_CACHEDIR_PKG); g_autofree gchar *xmlbfn = g_build_filename(cachedirpkg, "quirks.xmlb", NULL); file = g_file_new_for_path(xmlbfn); } diff --git a/libfwupdplugin/fu-smbios.c b/libfwupdplugin/fu-smbios.c index 63ee451a4..73e350f07 100644 --- a/libfwupdplugin/fu-smbios.c +++ b/libfwupdplugin/fu-smbios.c @@ -22,6 +22,7 @@ #include "fu-common.h" #include "fu-kenv.h" #include "fu-mem.h" +#include "fu-path.h" #include "fu-smbios-private.h" #include "fu-string.h" @@ -857,7 +858,7 @@ fu_smbios_setup(FuSmbios *self, GError **error) g_return_val_if_fail(FU_IS_SMBIOS(self), FALSE); g_return_val_if_fail(error == NULL || *error == NULL, FALSE); - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); /* DMI */ path = g_build_filename(sysfsfwdir, "dmi", "tables", NULL); diff --git a/libfwupdplugin/fwupdplugin.h b/libfwupdplugin/fwupdplugin.h index acd778401..ed09b808e 100644 --- a/libfwupdplugin/fwupdplugin.h +++ b/libfwupdplugin/fwupdplugin.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 00ec67658..ff9cc61e5 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -70,8 +70,6 @@ LIBFWUPDPLUGIN_0.9.3 { LIBFWUPDPLUGIN_0.9.7 { global: - fu_common_mkdir_parent; - fu_common_rmtree; fu_device_get_metadata_boolean; fu_device_get_metadata_integer; fu_device_set_metadata_boolean; @@ -150,14 +148,12 @@ LIBFWUPDPLUGIN_1.0.5 { LIBFWUPDPLUGIN_1.0.6 { global: - fu_common_get_files_recursive; fu_plugin_get_config_value; local: *; } LIBFWUPDPLUGIN_1.0.5; LIBFWUPDPLUGIN_1.0.8 { global: - fu_common_get_path; fu_device_add_child; fu_device_add_parent_guid; fu_device_attach; @@ -209,7 +205,6 @@ LIBFWUPDPLUGIN_1.1.2 { fu_chunk_array_new_from_bytes; fu_chunk_new; fu_chunk_to_string; - fu_common_find_program_in_path; fu_device_add_counterpart_guid; fu_device_close; fu_device_ensure_id; @@ -382,7 +377,6 @@ LIBFWUPDPLUGIN_1.3.4 { LIBFWUPDPLUGIN_1.3.5 { global: - fu_common_fnmatch; fu_device_incorporate_flag; fu_plugin_is_open; local: *; @@ -478,7 +472,6 @@ LIBFWUPDPLUGIN_1.4.7 { LIBFWUPDPLUGIN_1.5.0 { global: fu_common_cpuid; - fu_common_filename_glob; fu_device_bind_driver; fu_device_dump_firmware; fu_device_report_metadata_post; @@ -846,7 +839,6 @@ LIBFWUPDPLUGIN_1.7.1 { fu_cfi_device_set_flash_id; fu_cfi_device_set_size; fu_common_check_full_disk_encryption; - fu_common_mkdir; fu_device_add_string; fu_device_get_internal_flags; fu_device_set_internal_flags; @@ -996,6 +988,14 @@ LIBFWUPDPLUGIN_1.8.2 { fu_memwrite_uint64; fu_memwrite_uint64_safe; fu_memwrite_uint8_safe; + fu_path_find_program; + fu_path_fnmatch; + fu_path_from_kind; + fu_path_get_files; + fu_path_glob; + fu_path_mkdir; + fu_path_mkdir_parent; + fu_path_rmtree; fu_progress_add_step; fu_progress_get_name; fu_progress_set_name; diff --git a/libfwupdplugin/meson.build b/libfwupdplugin/meson.build index 9c2294bde..8bcb37cc9 100644 --- a/libfwupdplugin/meson.build +++ b/libfwupdplugin/meson.build @@ -23,6 +23,7 @@ fwupdplugin_src = [ 'fu-bytes.c', # fuzzing 'fu-kernel.c', # fuzzing 'fu-dump.c', # fuzzing + 'fu-path.c', # fuzzing 'fu-common-cab.c', 'fu-common-guid.c', 'fu-common-version.c', # fuzzing @@ -101,6 +102,7 @@ fwupdplugin_headers = [ 'fu-crc.h', 'fu-mem.h', 'fu-dump.h', + 'fu-path.h', 'fu-bytes.h', 'fu-kernel.h', 'fu-common-cab.h', diff --git a/plugins/acpi-dmar/fu-plugin-acpi-dmar.c b/plugins/acpi-dmar/fu-plugin-acpi-dmar.c index 68ab7c337..0eb082e31 100644 --- a/plugins/acpi-dmar/fu-plugin-acpi-dmar.c +++ b/plugins/acpi-dmar/fu-plugin-acpi-dmar.c @@ -31,7 +31,7 @@ fu_plugin_acpi_dmar_add_security_attrs(FuPlugin *plugin, FuSecurityAttrs *attrs) fu_security_attrs_append(attrs, attr); /* load DMAR table */ - path = fu_common_get_path(FU_PATH_KIND_ACPI_TABLES); + path = fu_path_from_kind(FU_PATH_KIND_ACPI_TABLES); fn = g_build_filename(path, "DMAR", NULL); blob = fu_bytes_get_contents(fn, &error_local); if (blob == NULL) { diff --git a/plugins/acpi-facp/fu-plugin-acpi-facp.c b/plugins/acpi-facp/fu-plugin-acpi-facp.c index 8d3f130c0..0db6f1bb3 100644 --- a/plugins/acpi-facp/fu-plugin-acpi-facp.c +++ b/plugins/acpi-facp/fu-plugin-acpi-facp.c @@ -27,7 +27,7 @@ fu_plugin_acpi_facp_add_security_attrs(FuPlugin *plugin, FuSecurityAttrs *attrs) fu_security_attrs_append(attrs, attr); /* load FACP table */ - path = fu_common_get_path(FU_PATH_KIND_ACPI_TABLES); + path = fu_path_from_kind(FU_PATH_KIND_ACPI_TABLES); fn = g_build_filename(path, "FACP", NULL); blob = fu_bytes_get_contents(fn, &error_local); if (blob == NULL) { diff --git a/plugins/acpi-ivrs/fu-plugin-acpi-ivrs.c b/plugins/acpi-ivrs/fu-plugin-acpi-ivrs.c index 2daa94f9b..6ac7c4ec5 100644 --- a/plugins/acpi-ivrs/fu-plugin-acpi-ivrs.c +++ b/plugins/acpi-ivrs/fu-plugin-acpi-ivrs.c @@ -32,7 +32,7 @@ fu_plugin_acpi_ivrs_add_security_attrs(FuPlugin *plugin, FuSecurityAttrs *attrs) fu_security_attrs_append(attrs, attr); /* load IVRS table */ - path = fu_common_get_path(FU_PATH_KIND_ACPI_TABLES); + path = fu_path_from_kind(FU_PATH_KIND_ACPI_TABLES); fn = g_build_filename(path, "IVRS", NULL); blob = fu_bytes_get_contents(fn, &error_local); if (blob == NULL) { diff --git a/plugins/acpi-phat/fu-plugin-acpi-phat.c b/plugins/acpi-phat/fu-plugin-acpi-phat.c index 8825386af..466cbbdc6 100644 --- a/plugins/acpi-phat/fu-plugin-acpi-phat.c +++ b/plugins/acpi-phat/fu-plugin-acpi-phat.c @@ -31,7 +31,7 @@ fu_plugin_acpi_phat_coldplug(FuPlugin *plugin, FuProgress *progress, GError **er g_autoptr(FuFirmware) phat = fu_acpi_phat_new(); g_autoptr(GBytes) blob = NULL; - path = fu_common_get_path(FU_PATH_KIND_ACPI_TABLES); + path = fu_path_from_kind(FU_PATH_KIND_ACPI_TABLES); fn = g_build_filename(path, "PHAT", NULL); blob = fu_bytes_get_contents(fn, error); if (blob == NULL) diff --git a/plugins/ata/fu-ata-device.c b/plugins/ata/fu-ata-device.c index 0c0cf83c0..64dd438b9 100644 --- a/plugins/ata/fu-ata-device.c +++ b/plugins/ata/fu-ata-device.c @@ -284,7 +284,7 @@ fu_ata_device_parse_vendor_name(FuAtaDevice *self, const gchar *name) /* find match */ for (guint i = 0; map_name[i].prefix != NULL; i++) { - if (fu_common_fnmatch(map_name[i].prefix, name_up)) { + if (fu_path_fnmatch(map_name[i].prefix, name_up)) { name += strlen(map_name[i].prefix) - 1; fu_device_set_vendor(FU_DEVICE(self), map_name[i].name); vendor_id = g_strdup_printf("ATA:0x%X", map_name[i].vid); @@ -295,7 +295,7 @@ fu_ata_device_parse_vendor_name(FuAtaDevice *self, const gchar *name) /* fall back to fuzzy match */ if (vendor_id == NULL) { for (guint i = 0; map_fuzzy[i].prefix != NULL; i++) { - if (fu_common_fnmatch(map_fuzzy[i].prefix, name_up)) { + if (fu_path_fnmatch(map_fuzzy[i].prefix, name_up)) { fu_device_set_vendor(FU_DEVICE(self), map_fuzzy[i].name); vendor_id = g_strdup_printf("ATA:0x%X", map_fuzzy[i].vid); break; @@ -308,7 +308,7 @@ fu_ata_device_parse_vendor_name(FuAtaDevice *self, const gchar *name) g_autofree gchar *version_up = g_ascii_strup(fu_device_get_version(FU_DEVICE(self)), -1); for (guint i = 0; map_version[i].prefix != NULL; i++) { - if (fu_common_fnmatch(map_version[i].prefix, version_up)) { + if (fu_path_fnmatch(map_version[i].prefix, version_up)) { fu_device_set_vendor(FU_DEVICE(self), map_version[i].name); vendor_id = g_strdup_printf("ATA:0x%X", map_version[i].vid); break; diff --git a/plugins/bcm57xx/fu-bcm57xx-device.c b/plugins/bcm57xx/fu-bcm57xx-device.c index 1ce662163..4507ac4f3 100644 --- a/plugins/bcm57xx/fu-bcm57xx-device.c +++ b/plugins/bcm57xx/fu-bcm57xx-device.c @@ -83,7 +83,7 @@ fu_bcm57xx_device_probe(FuDevice *device, GError **error) g_debug("waiting for net devices to appear"); g_usleep(50 * 1000); } - ifaces = fu_common_filename_glob(fn, "en*", NULL); + ifaces = fu_path_glob(fn, "en*", NULL); if (ifaces == NULL || ifaces->len == 0) { fu_device_add_child(FU_DEVICE(self), FU_DEVICE(self->recovery)); } else { diff --git a/plugins/bios/fu-plugin-bios.c b/plugins/bios/fu-plugin-bios.c index 72bbd98ee..eda817f81 100644 --- a/plugins/bios/fu-plugin-bios.c +++ b/plugins/bios/fu-plugin-bios.c @@ -40,7 +40,7 @@ fu_plugin_bios_coldplug(FuPlugin *plugin, FuProgress *progress, GError **error) #endif /* get the directory of ESRT entries */ - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); esrt_path = g_build_filename(sysfsfwdir, "efi", "esrt", NULL); if (!g_file_test(esrt_path, G_FILE_TEST_IS_DIR)) { fu_plugin_add_flag(plugin, FWUPD_PLUGIN_FLAG_CAPSULES_UNSUPPORTED); diff --git a/plugins/dell-esrt/fu-plugin-dell-esrt.c b/plugins/dell-esrt/fu-plugin-dell-esrt.c index c393aaa93..58b098886 100644 --- a/plugins/dell-esrt/fu-plugin-dell-esrt.c +++ b/plugins/dell-esrt/fu-plugin-dell-esrt.c @@ -101,7 +101,7 @@ fu_plugin_dell_esrt_startup(FuPlugin *plugin, FuProgress *progress, GError **err g_autofree gchar *esrtdir = NULL; /* already exists */ - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); esrtdir = g_build_filename(sysfsfwdir, "efi", "esrt", NULL); if (g_file_test(esrtdir, G_FILE_TEST_EXISTS)) { g_set_error_literal(error, diff --git a/plugins/dell/fu-plugin-dell.c b/plugins/dell/fu-plugin-dell.c index 44c0e1ce1..ecb9d2ce4 100644 --- a/plugins/dell/fu-plugin-dell.c +++ b/plugins/dell/fu-plugin-dell.c @@ -935,7 +935,7 @@ fu_plugin_dell_startup(FuPlugin *plugin, FuProgress *progress, GError **error) * * Once unlocked, that will enable flashing capsules here too. */ - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); esrtdir = g_build_filename(sysfsfwdir, "efi", "esrt", NULL); if (g_file_test(esrtdir, G_FILE_TEST_EXISTS)) data->capsule_supported = TRUE; diff --git a/plugins/dell/fu-self-test.c b/plugins/dell/fu-self-test.c index 17fc6743f..38fa9692a 100644 --- a/plugins/dell/fu-self-test.c +++ b/plugins/dell/fu-self-test.c @@ -569,7 +569,7 @@ main(int argc, char **argv) (void)g_setenv("FWUPD_SYSFSFWDIR", testdatadir, TRUE); /* change behavior */ - sysfsdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); (void)g_setenv("FWUPD_UEFI_ESP_PATH", sysfsdir, TRUE); (void)g_setenv("FWUPD_UEFI_TEST", "1", TRUE); (void)g_setenv("FWUPD_DELL_FAKE_SMBIOS", "1", FALSE); diff --git a/plugins/dfu/fu-dfu-self-test.c b/plugins/dfu/fu-dfu-self-test.c index 1cf0a3f17..7a77462b2 100644 --- a/plugins/dfu/fu-dfu-self-test.c +++ b/plugins/dfu/fu-dfu-self-test.c @@ -30,7 +30,7 @@ fu_test_compare_lines(const gchar *txt1, const gchar *txt2, GError **error) g_autofree gchar *output = NULL; if (g_strcmp0(txt1, txt2) == 0) return TRUE; - if (fu_common_fnmatch(txt2, txt1)) + if (fu_path_fnmatch(txt2, txt1)) return TRUE; if (!g_file_set_contents("/tmp/a", txt1, -1, error)) return FALSE; diff --git a/plugins/flashrom/fu-flashrom-device.c b/plugins/flashrom/fu-flashrom-device.c index d8f570964..3334d51ee 100644 --- a/plugins/flashrom/fu-flashrom-device.c +++ b/plugins/flashrom/fu-flashrom-device.c @@ -166,9 +166,9 @@ fu_flashrom_device_prepare(FuDevice *device, /* if the original firmware doesn't exist, grab it now */ basename = g_strdup_printf("flashrom-%s.bin", fu_device_get_id(device)); - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); firmware_orig = g_build_filename(localstatedir, "builder", basename, NULL); - if (!fu_common_mkdir_parent(firmware_orig, error)) + if (!fu_path_mkdir_parent(firmware_orig, error)) return FALSE; if (!g_file_test(firmware_orig, G_FILE_TEST_EXISTS)) { g_autoptr(GBytes) buf = NULL; diff --git a/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c b/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c index 247cf1bea..f453ed208 100644 --- a/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c +++ b/plugins/lenovo-thinklmi/fu-plugin-lenovo-thinklmi.c @@ -15,7 +15,7 @@ fu_plugin_lenovo_thinklmi_startup(FuPlugin *plugin, FuProgress *progress, GError g_autofree gchar *thinklmidir = NULL; /* already exists */ - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW_ATTRIB); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW_ATTRIB); thinklmidir = g_build_filename(sysfsfwdir, "thinklmi", NULL); if (!g_file_test(thinklmidir, G_FILE_TEST_EXISTS)) { g_set_error_literal(error, @@ -34,7 +34,7 @@ fu_plugin_lenovo_firmware_pending_change(gboolean *result, GError **error) g_autofree gchar *buf = NULL; g_autofree gchar *sysfsfwdir = NULL; g_autofree gchar *pending = NULL; - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW_ATTRIB); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW_ATTRIB); pending = g_build_filename(sysfsfwdir, "thinklmi", "attributes", "pending_reboot", NULL); /* we can't check, assume not locked */ @@ -57,7 +57,7 @@ fu_plugin_lenovo_firmware_locked(gboolean *locked, GError **error) g_autofree gchar *sysfsfwdir = NULL; g_autofree gchar *thinklmi = NULL; - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW_ATTRIB); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW_ATTRIB); thinklmi = g_build_filename(sysfsfwdir, "thinklmi", "attributes", diff --git a/plugins/lenovo-thinklmi/fu-self-test.c b/plugins/lenovo-thinklmi/fu-self-test.c index af20c10cd..fc70edbbc 100644 --- a/plugins/lenovo-thinklmi/fu-self-test.c +++ b/plugins/lenovo-thinklmi/fu-self-test.c @@ -154,7 +154,7 @@ main(int argc, char **argv) (void)g_setenv("FWUPD_SYSFSFWDIR", testdatadir, TRUE); /* change behavior of UEFI plugin for test mode */ - sysfsdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); (void)g_setenv("FWUPD_UEFI_ESP_PATH", sysfsdir, TRUE); (void)g_setenv("FWUPD_UEFI_TEST", "1", TRUE); diff --git a/plugins/linux-lockdown/fu-plugin-linux-lockdown.c b/plugins/linux-lockdown/fu-plugin-linux-lockdown.c index debaddf32..9b1f0328b 100644 --- a/plugins/linux-lockdown/fu-plugin-linux-lockdown.c +++ b/plugins/linux-lockdown/fu-plugin-linux-lockdown.c @@ -100,7 +100,7 @@ fu_plugin_linux_lockdown_startup(FuPlugin *plugin, FuProgress *progress, GError g_autofree gchar *path = NULL; g_autofree gchar *fn = NULL; - path = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_SECURITY); + path = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_SECURITY); fn = g_build_filename(path, "lockdown", NULL); if (!g_file_test(fn, G_FILE_TEST_EXISTS)) { g_set_error_literal(error, diff --git a/plugins/linux-swap/fu-plugin-linux-swap.c b/plugins/linux-swap/fu-plugin-linux-swap.c index 959c291e2..59f86d2a5 100644 --- a/plugins/linux-swap/fu-plugin-linux-swap.c +++ b/plugins/linux-swap/fu-plugin-linux-swap.c @@ -52,7 +52,7 @@ fu_plugin_linux_swap_startup(FuPlugin *plugin, FuProgress *progress, GError **er g_autofree gchar *fn = NULL; g_autofree gchar *procfs = NULL; - procfs = fu_common_get_path(FU_PATH_KIND_PROCFS); + procfs = fu_path_from_kind(FU_PATH_KIND_PROCFS); fn = g_build_filename(procfs, "swaps", NULL); if (!g_file_test(fn, G_FILE_TEST_EXISTS)) { g_set_error_literal(error, diff --git a/plugins/linux-tainted/fu-plugin-linux-tainted.c b/plugins/linux-tainted/fu-plugin-linux-tainted.c index bcc0d603b..313b2263e 100644 --- a/plugins/linux-tainted/fu-plugin-linux-tainted.c +++ b/plugins/linux-tainted/fu-plugin-linux-tainted.c @@ -50,7 +50,7 @@ fu_plugin_linux_tainted_startup(FuPlugin *plugin, FuProgress *progress, GError * g_autofree gchar *fn = NULL; g_autofree gchar *procfs = NULL; - procfs = fu_common_get_path(FU_PATH_KIND_PROCFS); + procfs = fu_path_from_kind(FU_PATH_KIND_PROCFS); fn = g_build_filename(procfs, "sys", "kernel", "tainted", NULL); data->file = g_file_new_for_path(fn); data->monitor = g_file_monitor(data->file, G_FILE_MONITOR_NONE, NULL, error); diff --git a/plugins/modem-manager/fu-mm-device.c b/plugins/modem-manager/fu-mm-device.c index 2c3a34309..be75f4d6f 100644 --- a/plugins/modem-manager/fu-mm-device.c +++ b/plugins/modem-manager/fu-mm-device.c @@ -1433,7 +1433,7 @@ fu_mm_setup_firmware_dir(FuMmDevice *self, GError **error) g_autofree gchar *mm_fw_dir = NULL; /* create a directory to store firmware files for modem-manager plugin */ - cachedir = fu_common_get_path(FU_PATH_KIND_CACHEDIR_PKG); + cachedir = fu_path_from_kind(FU_PATH_KIND_CACHEDIR_PKG); mm_fw_dir = g_build_filename(cachedir, "modem-manager", "firmware", NULL); if (g_mkdir_with_parents(mm_fw_dir, 0700) == -1) { g_set_error(error, @@ -1460,7 +1460,7 @@ fu_mm_copy_firehose_prog(FuMmDevice *self, GBytes *prog, GError **error) g_autofree gchar *firehose_file_path = NULL; qcom_fw_dir = g_build_filename(self->firmware_path, "qcom", NULL); - if (!fu_common_mkdir_parent(qcom_fw_dir, error)) + if (!fu_path_mkdir_parent(qcom_fw_dir, error)) return FALSE; firehose_file_path = g_build_filename(qcom_fw_dir, "prog_firehose_sdx24.mbn", NULL); diff --git a/plugins/powerd/fu-plugin-powerd.c b/plugins/powerd/fu-plugin-powerd.c index bcefd6084..e6b63f1ec 100644 --- a/plugins/powerd/fu-plugin-powerd.c +++ b/plugins/powerd/fu-plugin-powerd.c @@ -26,7 +26,7 @@ fu_plugin_powerd_create_suspend_file(GError **error) g_autofree gchar *inhibitsuspend_filename = NULL; g_autofree gchar *getpid_str = NULL; - lockdir = fu_common_get_path(FU_PATH_KIND_LOCKDIR); + lockdir = fu_path_from_kind(FU_PATH_KIND_LOCKDIR); inhibitsuspend_filename = g_build_filename(lockdir, "power_override", "fwupd.lock", NULL); getpid_str = g_strdup_printf("%d", getpid()); if (!g_file_set_contents(inhibitsuspend_filename, getpid_str, -1, error)) { @@ -43,7 +43,7 @@ fu_plugin_powerd_delete_suspend_file(GError **error) g_autofree gchar *lockdir = NULL; g_autoptr(GFile) inhibitsuspend_file = NULL; - lockdir = fu_common_get_path(FU_PATH_KIND_LOCKDIR); + lockdir = fu_path_from_kind(FU_PATH_KIND_LOCKDIR); inhibitsuspend_file = g_file_new_build_filename(lockdir, "power_override", "fwupd.lock", NULL); if (!g_file_delete(inhibitsuspend_file, NULL, &local_error) && diff --git a/plugins/redfish/fu-self-test.c b/plugins/redfish/fu-self-test.c index 5315fe293..dabd21781 100644 --- a/plugins/redfish/fu-self-test.c +++ b/plugins/redfish/fu-self-test.c @@ -49,7 +49,7 @@ fu_test_self_init(FuTest *self) /* running as an installed test */ if (fu_test_is_installed_test()) { - g_autofree gchar *plugindir = fu_common_get_path(FU_PATH_KIND_PLUGINDIR_PKG); + g_autofree gchar *plugindir = fu_path_from_kind(FU_PATH_KIND_PLUGINDIR_PKG); pluginfn = g_build_filename(plugindir, "libfu_plugin_redfish." G_MODULE_SUFFIX, NULL); } else { diff --git a/plugins/tpm/fu-plugin-tpm.c b/plugins/tpm/fu-plugin-tpm.c index 0eb968c91..e8b38ee42 100644 --- a/plugins/tpm/fu-plugin-tpm.c +++ b/plugins/tpm/fu-plugin-tpm.c @@ -344,7 +344,7 @@ fu_plugin_tpm_startup(FuPlugin *plugin, FuProgress *progress, GError **error) g_autofree gchar *fn_pcrs = NULL; /* look for TPM v1.2 */ - sysfstpmdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_TPM); + sysfstpmdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_TPM); fn_pcrs = g_build_filename(sysfstpmdir, "tpm0", "pcrs", NULL); if (g_file_test(fn_pcrs, G_FILE_TEST_EXISTS) && g_getenv("FWUPD_FORCE_TPM2") == NULL) { data->tpm_device = fu_tpm_v1_device_new(fu_plugin_get_context(plugin)); diff --git a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c index 258a33110..d8f5235f5 100644 --- a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c +++ b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c @@ -199,7 +199,7 @@ fu_plugin_uefi_capsule_get_splash_data(guint width, guint height, GError **error g_autoptr(GBytes) blob_archive = NULL; /* load archive */ - datadir_pkg = fu_common_get_path(FU_PATH_KIND_DATADIR_PKG); + datadir_pkg = fu_path_from_kind(FU_PATH_KIND_DATADIR_PKG); filename_archive = g_build_filename(datadir_pkg, "uefi-capsule-ux.tar.xz", NULL); blob_archive = fu_bytes_get_contents(filename_archive, error); if (blob_archive == NULL) @@ -276,7 +276,7 @@ fu_plugin_uefi_capsule_write_splash_data(FuPlugin *plugin, directory = fu_uefi_get_esp_path_for_os(device, esp_path); basename = g_strdup_printf("fwupd-%s.cap", FU_EFIVAR_GUID_UX_CAPSULE); fn = g_build_filename(directory, "fw", basename, NULL); - if (!fu_common_mkdir_parent(fn, error)) + if (!fu_path_mkdir_parent(fn, error)) return FALSE; ofile = g_file_new_for_path(fn); ostream = diff --git a/plugins/uefi-capsule/fu-uefi-backend-linux.c b/plugins/uefi-capsule/fu-uefi-backend-linux.c index 923533fc7..b64864d91 100644 --- a/plugins/uefi-capsule/fu-uefi-backend-linux.c +++ b/plugins/uefi-capsule/fu-uefi-backend-linux.c @@ -89,7 +89,7 @@ fu_uefi_backend_linux_device_new(FuUefiBackendLinux *self, const gchar *path) static gboolean fu_uefi_backend_linux_check_efivarfs(FuUefiBackendLinux *self, GError **error) { - g_autofree gchar *sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + g_autofree gchar *sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); g_autofree gchar *sysfsefivardir = g_build_filename(sysfsfwdir, "efi", "efivars", NULL); g_autoptr(GUnixMountEntry) mount = g_unix_mount_at(sysfsefivardir, NULL); @@ -138,7 +138,7 @@ fu_uefi_backend_linux_coldplug(FuBackend *backend, FuProgress *progress, GError return FALSE; /* get the directory of ESRT entries */ - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); esrt_path = g_build_filename(sysfsfwdir, "efi", "esrt", NULL); esrt_entries = g_build_filename(esrt_path, "entries", NULL); dir = g_dir_open(esrt_entries, 0, error); @@ -210,7 +210,7 @@ fu_uefi_backend_linux_setup(FuBackend *backend, FuProgress *progress, GError **e /* check SMBIOS for 'UEFI Specification is supported' */ if (!fu_uefi_backend_linux_check_smbios_enabled(fu_backend_get_context(backend), &error_local)) { - g_autofree gchar *fw = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + g_autofree gchar *fw = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); g_autofree gchar *fn = g_build_filename(fw, "efi", NULL); if (g_file_test(fn, G_FILE_TEST_EXISTS)) { g_warning("SMBIOS BIOS Characteristics Extension Byte 2 is invalid -- " diff --git a/plugins/uefi-capsule/fu-uefi-bgrt.c b/plugins/uefi-capsule/fu-uefi-bgrt.c index 57fa42f4b..c75c34513 100644 --- a/plugins/uefi-capsule/fu-uefi-bgrt.c +++ b/plugins/uefi-capsule/fu-uefi-bgrt.c @@ -34,7 +34,7 @@ fu_uefi_bgrt_setup(FuUefiBgrt *self, GError **error) g_return_val_if_fail(FU_IS_UEFI_BGRT(self), FALSE); - sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); bgrtdir = g_build_filename(sysfsfwdir, "acpi", "bgrt", NULL); if (!g_file_test(bgrtdir, G_FILE_TEST_EXISTS)) { g_set_error_literal(error, diff --git a/plugins/uefi-capsule/fu-uefi-cod-device.c b/plugins/uefi-capsule/fu-uefi-cod-device.c index 29c6c87df..1bd4c6598 100644 --- a/plugins/uefi-capsule/fu-uefi-cod-device.c +++ b/plugins/uefi-capsule/fu-uefi-cod-device.c @@ -172,7 +172,7 @@ fu_uefi_cod_device_write_firmware(FuDevice *device, return FALSE; basename = g_strdup_printf("fwupd-%s.cap", fu_uefi_device_get_guid(self)); cod_path = g_build_filename(esp_path, "EFI", "UpdateCapsule", basename, NULL); - if (!fu_common_mkdir_parent(cod_path, error)) + if (!fu_path_mkdir_parent(cod_path, error)) return FALSE; if (!fu_bytes_set_contents(cod_path, fw, error)) return FALSE; diff --git a/plugins/uefi-capsule/fu-uefi-common.c b/plugins/uefi-capsule/fu-uefi-common.c index 0a5ac863d..de7a908e0 100644 --- a/plugins/uefi-capsule/fu-uefi-common.c +++ b/plugins/uefi-capsule/fu-uefi-common.c @@ -32,7 +32,7 @@ fu_uefi_bootmgr_get_suffix(GError **error) #endif {0, NULL} }; - g_autofree gchar *sysfsfwdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_FW); + g_autofree gchar *sysfsfwdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_FW); g_autofree gchar *sysfsefidir = g_build_filename(sysfsfwdir, "efi", NULL); firmware_bits = fu_uefi_read_file_as_uint64(sysfsefidir, "fw_platform_size"); if (firmware_bits == 0) { @@ -98,7 +98,7 @@ fu_uefi_get_built_app_path(GError **error) suffix = fu_uefi_bootmgr_get_suffix(error); if (suffix == NULL) return NULL; - prefix = fu_common_get_path(FU_PATH_KIND_EFIAPPDIR); + prefix = fu_path_from_kind(FU_PATH_KIND_EFIAPPDIR); source_path = g_strdup_printf("%s/fwupd%s.efi", prefix, suffix); source_path_signed = g_strdup_printf("%s.signed", source_path); @@ -140,7 +140,7 @@ fu_uefi_get_framebuffer_size(guint32 *width, guint32 *height, GError **error) g_autofree gchar *sysfsdriverdir = NULL; g_autofree gchar *fbdir = NULL; - sysfsdriverdir = fu_common_get_path(FU_PATH_KIND_SYSFSDIR_DRIVERS); + sysfsdriverdir = fu_path_from_kind(FU_PATH_KIND_SYSFSDIR_DRIVERS); fbdir = g_build_filename(sysfsdriverdir, "efi-framebuffer", "efi-framebuffer.0", NULL); if (!g_file_test(fbdir, G_FILE_TEST_EXISTS)) { g_set_error_literal(error, diff --git a/plugins/uefi-capsule/fu-uefi-device.c b/plugins/uefi-capsule/fu-uefi-device.c index f6d7caa3f..6603d38ac 100644 --- a/plugins/uefi-capsule/fu-uefi-device.c +++ b/plugins/uefi-capsule/fu-uefi-device.c @@ -536,13 +536,13 @@ fu_uefi_device_cleanup_esp(FuDevice *device, GError **error) return TRUE; /* delete any files matching the glob in the ESP */ - files = fu_common_get_files_recursive(esp_path, error); + files = fu_path_get_files(esp_path, error); if (files == NULL) return FALSE; pattern = g_build_filename(esp_path, "EFI/*/fw/fwupd*.cap", NULL); for (guint i = 0; i < files->len; i++) { const gchar *fn = g_ptr_array_index(files, i); - if (fu_common_fnmatch(pattern, fn)) { + if (fu_path_fnmatch(pattern, fn)) { g_autoptr(GFile) file = g_file_new_for_path(fn); g_debug("deleting %s", fn); if (!g_file_delete(file, NULL, error)) diff --git a/plugins/uefi-capsule/fu-uefi-grub-device.c b/plugins/uefi-capsule/fu-uefi-grub-device.c index 87cc21743..bb57cb7b4 100644 --- a/plugins/uefi-capsule/fu-uefi-grub-device.c +++ b/plugins/uefi-capsule/fu-uefi-grub-device.c @@ -29,7 +29,7 @@ fu_uefi_grub_device_mkconfig(FuDevice *device, g_autofree gchar *grub_mkconfig = NULL; g_autofree gchar *grub_reboot = NULL; g_autofree gchar *grub_target = NULL; - g_autofree gchar *localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + g_autofree gchar *localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); g_autofree gchar *output = NULL; g_autoptr(GString) str = g_string_new(NULL); @@ -45,9 +45,9 @@ fu_uefi_grub_device_mkconfig(FuDevice *device, } /* find grub-mkconfig */ - grub_mkconfig = fu_common_find_program_in_path("grub-mkconfig", NULL); + grub_mkconfig = fu_path_find_program("grub-mkconfig", NULL); if (grub_mkconfig == NULL) - grub_mkconfig = fu_common_find_program_in_path("grub2-mkconfig", NULL); + grub_mkconfig = fu_path_find_program("grub2-mkconfig", NULL); if (grub_mkconfig == NULL) { g_set_error_literal(error, G_IO_ERROR, @@ -57,9 +57,9 @@ fu_uefi_grub_device_mkconfig(FuDevice *device, } /* find grub-reboot */ - grub_reboot = fu_common_find_program_in_path("grub-reboot", NULL); + grub_reboot = fu_path_find_program("grub-reboot", NULL); if (grub_reboot == NULL) - grub_reboot = fu_common_find_program_in_path("grub2-reboot", NULL); + grub_reboot = fu_path_find_program("grub2-reboot", NULL); if (grub_reboot == NULL) { g_set_error_literal(error, G_IO_ERROR, @@ -143,7 +143,7 @@ fu_uefi_grub_device_write_firmware(FuDevice *device, directory = fu_uefi_get_esp_path_for_os(device, esp_path); basename = g_strdup_printf("fwupd-%s.cap", fw_class); fn = g_build_filename(directory, "fw", basename, NULL); - if (!fu_common_mkdir_parent(fn, error)) + if (!fu_path_mkdir_parent(fn, error)) return FALSE; fixed_fw = fu_uefi_device_fixup_firmware(self, fw, error); if (fixed_fw == NULL) diff --git a/plugins/uefi-capsule/fu-uefi-nvram-device.c b/plugins/uefi-capsule/fu-uefi-nvram-device.c index 4744378bf..28413fb37 100644 --- a/plugins/uefi-capsule/fu-uefi-nvram-device.c +++ b/plugins/uefi-capsule/fu-uefi-nvram-device.c @@ -81,7 +81,7 @@ fu_uefi_nvram_device_write_firmware(FuDevice *device, directory = fu_uefi_get_esp_path_for_os(device, esp_path); basename = g_strdup_printf("fwupd-%s.cap", fw_class); fn = g_build_filename(directory, "fw", basename, NULL); - if (!fu_common_mkdir_parent(fn, error)) + if (!fu_path_mkdir_parent(fn, error)) return FALSE; fixed_fw = fu_uefi_device_fixup_firmware(self, fw, error); if (fixed_fw == NULL) diff --git a/plugins/uefi-dbx/fu-uefi-dbx-common.c b/plugins/uefi-dbx/fu-uefi-dbx-common.c index b6b2f4532..4da3c59f7 100644 --- a/plugins/uefi-dbx/fu-uefi-dbx-common.c +++ b/plugins/uefi-dbx/fu-uefi-dbx-common.c @@ -43,7 +43,7 @@ fu_uefi_dbx_signature_list_validate_volume(FuEfiSignatureList *siglist, esp_path = fu_volume_get_mount_point(esp); if (esp_path == NULL) return TRUE; - files = fu_common_get_files_recursive(esp_path, error); + files = fu_path_get_files(esp_path, error); if (files == NULL) return FALSE; diff --git a/src/fu-config.c b/src/fu-config.c index 38b8d743d..375886f19 100644 --- a/src/fu-config.c +++ b/src/fu-config.c @@ -15,6 +15,7 @@ #include "fu-bytes.h" #include "fu-common.h" #include "fu-config.h" +#include "fu-path.h" #include "fu-string.h" enum { SIGNAL_CHANGED, SIGNAL_LAST }; @@ -305,8 +306,8 @@ fu_config_set_key_value(FuConfig *self, const gchar *key, const gchar *value, GE gboolean fu_config_load(FuConfig *self, GError **error) { - g_autofree gchar *configdir_mut = fu_common_get_path(FU_PATH_KIND_LOCALCONFDIR_PKG); - g_autofree gchar *configdir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR_PKG); + g_autofree gchar *configdir_mut = fu_path_from_kind(FU_PATH_KIND_LOCALCONFDIR_PKG); + g_autofree gchar *configdir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR_PKG); g_return_val_if_fail(FU_IS_CONFIG(self), FALSE); g_return_val_if_fail(self->filenames->len == 0, FALSE); diff --git a/src/fu-engine-helper.c b/src/fu-engine-helper.c index e21db2787..ad8c5bce4 100644 --- a/src/fu-engine-helper.c +++ b/src/fu-engine-helper.c @@ -12,6 +12,7 @@ #include "fu-engine-helper.h" #include "fu-engine.h" +#include "fu-path.h" static FwupdRelease * fu_engine_get_release_with_tag(FuEngine *self, @@ -94,12 +95,12 @@ fu_engine_update_motd(FuEngine *self, GError **error) target = g_build_filename(g_getenv("RUNTIME_DIRECTORY"), MOTD_FILE, NULL); /* otherwise use the cache directory */ } else { - g_autofree gchar *directory = fu_common_get_path(FU_PATH_KIND_CACHEDIR_PKG); + g_autofree gchar *directory = fu_path_from_kind(FU_PATH_KIND_CACHEDIR_PKG); target = g_build_filename(directory, MOTD_DIR, MOTD_FILE, NULL); } /* create the directory and file, even if zero devices; we want an empty file then */ - if (!fu_common_mkdir_parent(target, error)) + if (!fu_path_mkdir_parent(target, error)) return FALSE; /* nag about syncing or updating, but never both */ diff --git a/src/fu-engine.c b/src/fu-engine.c index 030cc9bbf..62e9141ce 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -62,6 +62,7 @@ #include "fu-kenv.h" #include "fu-keyring-utils.h" #include "fu-mutex.h" +#include "fu-path.h" #include "fu-plugin-list.h" #include "fu-plugin-private.h" #include "fu-plugin.h" @@ -868,9 +869,9 @@ fu_engine_verify_update(FuEngine *self, xb_builder_import_node(builder, component); /* save silo */ - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); fn = g_strdup_printf("%s/verify/%s.xml", localstatedir, device_id); - if (!fu_common_mkdir_parent(fn, error)) + if (!fu_path_mkdir_parent(fn, error)) return FALSE; file = g_file_new_for_path(fn); silo = xb_builder_compile(builder, XB_BUILDER_COMPILE_FLAG_NONE, NULL, error); @@ -946,7 +947,7 @@ fu_engine_verify_from_local_metadata(FuEngine *self, FuDevice *device, GError ** g_autoptr(XbNode) release = NULL; g_autoptr(XbSilo) silo = NULL; - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); fn = g_strdup_printf("%s/verify/%s.xml", localstatedir, fu_device_get_id(device)); file = g_file_new_for_path(fn); if (!g_file_query_exists(file, NULL)) { @@ -1207,7 +1208,7 @@ fu_engine_require_vercmp(XbNode *req, const gchar *version, FwupdVersionFormat f rc = fu_common_vercmp_full(version, version_req, fmt); ret = rc >= 0; } else if (g_strcmp0(tmp, "glob") == 0) { - ret = fu_common_fnmatch(version_req, version); + ret = fu_path_fnmatch(version_req, version); } else if (g_strcmp0(tmp, "regex") == 0) { ret = g_regex_match_simple(version_req, version, 0, 0); } else { @@ -1655,7 +1656,7 @@ fu_engine_check_trust(FuEngine *self, FuRelease *release, GError **error) { if (fu_config_get_only_trusted(self->config) && (fu_release_get_trust_flags(release) & FWUPD_TRUST_FLAG_PAYLOAD) == 0) { - g_autofree gchar *sysconfdir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR_PKG); + g_autofree gchar *sysconfdir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR_PKG); g_autofree gchar *fn = g_build_filename(sysconfdir, "daemon.conf", NULL); g_set_error(error, FWUPD_ERROR, @@ -2232,8 +2233,8 @@ fu_engine_offline_setup(GError **error) #ifdef HAVE_GIO_UNIX gint rc; g_autofree gchar *filename = NULL; - g_autofree gchar *symlink_target = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); - g_autofree gchar *trigger = fu_common_get_path(FU_PATH_KIND_OFFLINE_TRIGGER); + g_autofree gchar *symlink_target = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); + g_autofree gchar *trigger = fu_path_from_kind(FU_PATH_KIND_OFFLINE_TRIGGER); g_return_val_if_fail(error == NULL || *error == NULL, FALSE); @@ -2269,7 +2270,7 @@ fu_engine_offline_setup(GError **error) static gboolean fu_engine_offline_invalidate(GError **error) { - g_autofree gchar *trigger = fu_common_get_path(FU_PATH_KIND_OFFLINE_TRIGGER); + g_autofree gchar *trigger = fu_path_from_kind(FU_PATH_KIND_OFFLINE_TRIGGER); g_autoptr(GError) error_local = NULL; g_autoptr(GFile) file1 = NULL; @@ -2345,7 +2346,7 @@ fu_engine_schedule_update(FuEngine *self, } /* create directory */ - dirname = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + dirname = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); file = g_file_new_for_path(dirname); if (!g_file_query_exists(file, NULL)) { if (!g_file_make_directory_with_parents(file, NULL, error)) @@ -2670,7 +2671,7 @@ fu_engine_device_check_power(FuEngine *self, GError **error) { if (flags & FWUPD_INSTALL_FLAG_IGNORE_POWER) { - g_autofree gchar *configdir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR_PKG); + g_autofree gchar *configdir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR_PKG); g_autofree gchar *configfile = g_build_filename(configdir, "daemon.conf", NULL); g_warning("Ignoring deprecated flag provided by client " "'FWUPD_INSTALL_FLAG_IGNORE_POWER'. To ignore power levels, modify %s", @@ -3369,7 +3370,7 @@ fu_engine_create_metadata(FuEngine *self, XbBuilder *builder, FwupdRemote *remot /* find all files in directory */ path = fwupd_remote_get_filename_cache(remote); - files = fu_common_get_files_recursive(path, error); + files = fu_path_get_files(path, error); if (files == NULL) return FALSE; @@ -3705,12 +3706,12 @@ fu_engine_load_metadata_store_local(FuEngine *self, FuPathKind path_kind, GError **error) { - g_autofree gchar *fn = fu_common_get_path(path_kind); + g_autofree gchar *fn = fu_path_from_kind(path_kind); g_autofree gchar *metadata_path = g_build_filename(fn, "local.d", NULL); g_autoptr(GError) error_local = NULL; g_autoptr(GPtrArray) metadata_fns = NULL; - metadata_fns = fu_common_filename_glob(metadata_path, "*.xml", &error_local); + metadata_fns = fu_path_glob(metadata_path, "*.xml", &error_local); if (metadata_fns == NULL) { g_debug("ignoring: %s", error_local->message); return TRUE; @@ -3841,7 +3842,7 @@ fu_engine_load_metadata_store(FuEngine *self, FuEngineLoadFlags flags, GError ** if (xmlb == NULL) return FALSE; } else { - g_autofree gchar *cachedirpkg = fu_common_get_path(FU_PATH_KIND_CACHEDIR_PKG); + g_autofree gchar *cachedirpkg = fu_path_from_kind(FU_PATH_KIND_CACHEDIR_PKG); g_autofree gchar *xmlbfn = g_build_filename(cachedirpkg, "metadata.xmlb", NULL); xmlb = g_file_new_for_path(xmlbfn); } @@ -6005,7 +6006,7 @@ fu_engine_is_plugin_name_enabled(FuEngine *self, const gchar *name) return TRUE; for (guint i = 0; i < self->plugin_filter->len; i++) { const gchar *name_tmp = g_ptr_array_index(self->plugin_filter, i); - if (fu_common_fnmatch(name_tmp, name)) + if (fu_path_fnmatch(name_tmp, name)) return TRUE; } return FALSE; @@ -6352,7 +6353,7 @@ fu_engine_load_plugins(FuEngine *self, FuProgress *progress, GError **error) fu_progress_add_step(progress, FWUPD_STATUS_LOADING, 87, "load"); /* search */ - plugin_path = fu_common_get_path(FU_PATH_KIND_PLUGINDIR_PKG); + plugin_path = fu_path_from_kind(FU_PATH_KIND_PLUGINDIR_PKG); dir = g_dir_open(plugin_path, 0, error); if (dir == NULL) return FALSE; @@ -6883,8 +6884,8 @@ fu_engine_ensure_paths_exist(GError **error) FU_PATH_KIND_CACHEDIR_PKG, FU_PATH_KIND_LAST}; for (guint i = 0; path_kinds[i] != FU_PATH_KIND_LAST; i++) { - g_autofree gchar *fn = fu_common_get_path(path_kinds[i]); - if (!fu_common_mkdir(fn, error)) + g_autofree gchar *fn = fu_path_from_kind(path_kinds[i]); + if (!fu_path_mkdir(fn, error)) return FALSE; } return TRUE; @@ -6911,7 +6912,7 @@ fu_engine_load_local_metadata_watches(FuEngine *self, GError **error) GFileMonitor *monitor; g_autoptr(GFile) file = NULL; g_autoptr(GError) error_local = NULL; - g_autofree gchar *base = fu_common_get_path(path_kinds[i]); + g_autofree gchar *base = fu_path_from_kind(path_kinds[i]); g_autofree gchar *fn = g_build_filename(base, "local.d", NULL); file = g_file_new_for_path(fn); @@ -7559,9 +7560,9 @@ fu_engine_init(FuEngine *self) /* setup Jcat context */ self->jcat_context = jcat_context_new(); - keyring_path = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + keyring_path = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); jcat_context_set_keyring_path(self->jcat_context, keyring_path); - sysconfdir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR); + sysconfdir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR); pkidir_fw = g_build_filename(sysconfdir, "pki", "fwupd", NULL); jcat_context_add_public_keys(self->jcat_context, pkidir_fw); pkidir_md = g_build_filename(sysconfdir, "pki", "fwupd-metadata", NULL); diff --git a/src/fu-firmware-builder.c b/src/fu-firmware-builder.c index 01b6783bf..346b92ced 100644 --- a/src/fu-firmware-builder.c +++ b/src/fu-firmware-builder.c @@ -204,7 +204,7 @@ fu_firmware_builder_process(GBytes *bytes, g_return_val_if_fail(error == NULL || *error == NULL, NULL); /* find bwrap in the path */ - bwrap_fn = fu_common_find_program_in_path("bwrap", error); + bwrap_fn = fu_path_find_program("bwrap", error); if (bwrap_fn == NULL) return NULL; @@ -220,7 +220,7 @@ fu_firmware_builder_process(GBytes *bytes, return NULL; /* this is shared with the plugins */ - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); localstatebuilderdir = g_build_filename(localstatedir, "builder", NULL); /* launch bubblewrap and generate firmware */ @@ -277,7 +277,7 @@ fu_firmware_builder_process(GBytes *bytes, return NULL; /* cleanup temp directory */ - if (!fu_common_rmtree(tmpdir, error)) + if (!fu_path_rmtree(tmpdir, error)) return NULL; /* success */ diff --git a/src/fu-history.c b/src/fu-history.c index 1103dda28..eaa64eb0c 100644 --- a/src/fu-history.c +++ b/src/fu-history.c @@ -24,6 +24,7 @@ #include "fu-device-private.h" #include "fu-history.h" #include "fu-mutex.h" +#include "fu-path.h" #include "fu-security-attr.h" #define FU_HISTORY_CURRENT_SCHEMA_VERSION 7 @@ -465,7 +466,7 @@ fu_history_load(FuHistory *self, GError **error) g_return_val_if_fail(locker != NULL, FALSE); /* create directory */ - dirname = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + dirname = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); file = g_file_new_for_path(dirname); if (!g_file_query_exists(file, NULL)) { if (!g_file_make_directory_with_parents(file, NULL, error)) diff --git a/src/fu-offline.c b/src/fu-offline.c index 744346019..1d131943d 100644 --- a/src/fu-offline.c +++ b/src/fu-offline.c @@ -13,6 +13,7 @@ #include #include "fu-history.h" +#include "fu-path.h" #include "fu-plugin-private.h" #include "fu-spawn.h" #include "fu-util-common.h" @@ -141,8 +142,8 @@ main(int argc, char *argv[]) gint vercmp; guint cnt = 0; g_autofree gchar *link = NULL; - g_autofree gchar *target = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); - g_autofree gchar *trigger = fu_common_get_path(FU_PATH_KIND_OFFLINE_TRIGGER); + g_autofree gchar *target = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); + g_autofree gchar *trigger = fu_path_from_kind(FU_PATH_KIND_OFFLINE_TRIGGER); g_autoptr(FuHistory) history = NULL; g_autoptr(FwupdClient) client = NULL; g_autoptr(GError) error = NULL; diff --git a/src/fu-polkit-agent.c b/src/fu-polkit-agent.c index 61e7d2699..e322ea3d1 100644 --- a/src/fu-polkit-agent.c +++ b/src/fu-polkit-agent.c @@ -26,6 +26,7 @@ #include #include "fu-common.h" +#include "fu-path.h" #include "fu-polkit-agent.h" static pid_t agent_pid = 0; @@ -180,7 +181,7 @@ fu_polkit_agent_open(GError **error) return TRUE; /* find binary */ - pkttyagent_fn = fu_common_find_program_in_path("pkttyagent", error); + pkttyagent_fn = fu_path_find_program("pkttyagent", error); if (pkttyagent_fn == NULL) return FALSE; diff --git a/src/fu-remote-list.c b/src/fu-remote-list.c index b7e37cfb4..ef44e8767 100644 --- a/src/fu-remote-list.c +++ b/src/fu-remote-list.c @@ -23,6 +23,7 @@ #include "fwupd-remote-private.h" #include "fu-common.h" +#include "fu-path.h" #include "fu-remote-list.h" #include "fu-string.h" @@ -216,7 +217,7 @@ fu_remote_list_add_for_path(FuRemoteList *self, const gchar *path, GError **erro } /* set directory to store data */ - remotesdir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_METADATA); + remotesdir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_METADATA); fwupd_remote_set_remotes_dir(remote, remotesdir); /* load from keyfile */ @@ -389,10 +390,10 @@ fu_remote_list_reload(FuRemoteList *self, GError **error) g_ptr_array_set_size(self->monitors, 0); /* use sysremotes, and then fall back to /etc */ - remotesdir = fu_common_get_path(FU_PATH_KIND_SYSCONFDIR_PKG); + remotesdir = fu_path_from_kind(FU_PATH_KIND_SYSCONFDIR_PKG); if (!fu_remote_list_add_for_path(self, remotesdir, error)) return FALSE; - remotesdir_mut = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + remotesdir_mut = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); if (!fu_remote_list_add_for_path(self, remotesdir_mut, error)) return FALSE; @@ -428,7 +429,7 @@ fu_remote_list_load_metainfos(XbBuilder *builder, GError **error) g_autoptr(GDir) dir = NULL; /* pkg metainfo dir */ - datadir = fu_common_get_path(FU_PATH_KIND_DATADIR_PKG); + datadir = fu_path_from_kind(FU_PATH_KIND_DATADIR_PKG); metainfo_path = g_build_filename(datadir, "metainfo", NULL); if (!g_file_test(metainfo_path, G_FILE_TEST_EXISTS)) return TRUE; @@ -485,7 +486,7 @@ fu_remote_list_load(FuRemoteList *self, FuRemoteListLoadFlags flags, GError **er if (xmlb == NULL) return FALSE; } else { - g_autofree gchar *cachedirpkg = fu_common_get_path(FU_PATH_KIND_CACHEDIR_PKG); + g_autofree gchar *cachedirpkg = fu_path_from_kind(FU_PATH_KIND_CACHEDIR_PKG); g_autofree gchar *xmlbfn = g_build_filename(cachedirpkg, "metainfo.xmlb", NULL); xmlb = g_file_new_for_path(xmlbfn); } diff --git a/src/fu-self-test.c b/src/fu-self-test.c index 391d96bde..d0c104712 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -78,7 +78,7 @@ fu_self_test_mkroot(void) { if (g_file_test("/tmp/fwupd-self-test", G_FILE_TEST_EXISTS)) { g_autoptr(GError) error = NULL; - if (!fu_common_rmtree("/tmp/fwupd-self-test", &error)) + if (!fu_path_rmtree("/tmp/fwupd-self-test", &error)) g_warning("failed to mkroot: %s", error->message); } g_assert_cmpint(g_mkdir_with_parents("/tmp/fwupd-self-test/var/lib/fwupd", 0755), ==, 0); @@ -90,7 +90,7 @@ fu_test_compare_lines(const gchar *txt1, const gchar *txt2, GError **error) g_autofree gchar *output = NULL; if (g_strcmp0(txt1, txt2) == 0) return TRUE; - if (fu_common_fnmatch(txt2, txt1)) + if (fu_path_fnmatch(txt2, txt1)) return TRUE; if (!g_file_set_contents("/tmp/a", txt1, -1, error)) return FALSE; @@ -2126,7 +2126,7 @@ fu_engine_history_inherit(gconstpointer user_data) #endif /* delete history */ - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); history_db = g_build_filename(localstatedir, "pending.db", NULL); (void)g_unlink(history_db); @@ -3208,7 +3208,7 @@ fu_plugin_module_func(gconstpointer user_data) g_clear_error(&error); /* delete files */ - localstatedir = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + localstatedir = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); history_db = g_build_filename(localstatedir, "pending.db", NULL); (void)g_unlink(history_db); (void)g_unlink(pending_cap); @@ -3239,7 +3239,7 @@ fu_history_func(gconstpointer user_data) g_assert_nonnull(history); /* delete the database */ - dirname = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + dirname = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) return; filename = g_build_filename(dirname, "pending.db", NULL); diff --git a/src/fu-tool.c b/src/fu-tool.c index c9af06040..f9a40c0d2 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -139,7 +139,7 @@ fu_util_save_current_state(FuUtilPrivate *priv, GError **error) state = json_generator_to_data(json_generator, NULL); if (state == NULL) return FALSE; - dirname = fu_common_get_path(FU_PATH_KIND_LOCALSTATEDIR_PKG); + dirname = fu_path_from_kind(FU_PATH_KIND_LOCALSTATEDIR_PKG); filename = g_build_filename(dirname, "state.json", NULL); return g_file_set_contents(filename, state, -1, error); } @@ -212,10 +212,10 @@ fu_util_lock(FuUtilPrivate *priv, GError **error) if (use_user) { lockfn = fu_util_get_user_cache_path("fwupdtool"); } else { - g_autofree gchar *lockdir = fu_common_get_path(FU_PATH_KIND_LOCKDIR); + g_autofree gchar *lockdir = fu_path_from_kind(FU_PATH_KIND_LOCKDIR); lockfn = g_build_filename(lockdir, "fwupdtool", NULL); } - if (!fu_common_mkdir_parent(lockfn, error)) + if (!fu_path_mkdir_parent(lockfn, error)) return FALSE; priv->lock_fd = g_open(lockfn, O_RDWR | O_CREAT, S_IRWXU); if (priv->lock_fd < 0) { @@ -1255,7 +1255,7 @@ fu_util_download_if_required(FuUtilPrivate *priv, const gchar *perhapsfn, GError /* download the firmware to a cachedir */ filename = fu_util_get_user_cache_path(perhapsfn); - if (!fu_common_mkdir_parent(filename, error)) + if (!fu_path_mkdir_parent(filename, error)) return NULL; file = g_file_new_for_path(filename); if (!fwupd_client_download_file(priv->client, @@ -3139,7 +3139,7 @@ fu_util_esp_list(FuUtilPrivate *priv, gchar **values, GError **error) if (locker == NULL) return FALSE; mount_point = fu_volume_get_mount_point(volume); - files = fu_common_get_files_recursive(mount_point, error); + files = fu_path_get_files(mount_point, error); if (files == NULL) return FALSE; for (guint i = 0; i < files->len; i++) { diff --git a/src/fu-util.c b/src/fu-util.c index 86974a8eb..d7c3396e5 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -29,6 +29,7 @@ #include "fwupd-remote-private.h" #include "fu-bytes.h" +#include "fu-path.h" #include "fu-plugin-private.h" #include "fu-polkit-agent.h" #include "fu-progressbar.h" @@ -655,7 +656,7 @@ fu_util_download_if_required(FuUtilPrivate *priv, const gchar *perhapsfn, GError filename = fu_util_get_user_cache_path(perhapsfn); if (g_file_test(filename, G_FILE_TEST_EXISTS)) return g_steal_pointer(&filename); - if (!fu_common_mkdir_parent(filename, error)) + if (!fu_path_mkdir_parent(filename, error)) return NULL; blob = fwupd_client_download_bytes(priv->client, perhapsfn, @@ -3538,7 +3539,7 @@ static gboolean fu_util_check_polkit_actions(GError **error) { #ifdef HAVE_POLKIT - g_autofree gchar *directory = fu_common_get_path(FU_PATH_KIND_POLKIT_ACTIONS); + g_autofree gchar *directory = fu_path_from_kind(FU_PATH_KIND_POLKIT_ACTIONS); g_autofree gchar *filename = g_build_filename(directory, "org.freedesktop.fwupd.policy", NULL); if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {