[epiphany/pgriffis/web-extension/install-remove: 5/6] WebExtensions: Fix issues with install and remove
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/install-remove: 5/6] WebExtensions: Fix issues with install and remove
- Date: Wed, 6 Jul 2022 00:17:15 +0000 (UTC)
commit 03e8b7aa2f3a3bcc19516d7368aec8acd9bb2471
Author: Patrick Griffis <pgriffis igalia com>
Date: Thu Jun 30 11:03:24 2022 -0500
WebExtensions: Fix issues with install and remove
- For .xpi installs the parent directory wasn't created if needed
- For .xpi installs uninstall didn't work
- The base_location was set to the wrong path after install
- Added some more logging when we refuse to copy symlinks
- Fix a few leaks from g_file_get_path()s
lib/ephy-file-helpers.c | 2 ++
src/webextension/ephy-web-extension-manager.c | 35 ++++++++++++++++++---------
src/webextension/ephy-web-extension.c | 9 +++----
3 files changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 9bd27ac5f..18017f788 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -892,6 +892,8 @@ ephy_copy_directory (const char *source,
return;
}
}
+ } else {
+ g_warning ("Copying the file type of %s isn't supported.", source);
}
}
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index 1a9975ecc..3589397c3 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -377,29 +377,40 @@ ephy_web_extension_manager_install (EphyWebExtensionManager *self,
g_autoptr (GFileInfo) file_info = NULL;
gboolean is_xpi = FALSE;
g_autoptr (GError) error = NULL;
+ g_autoptr (GFile) web_extensions_dir = NULL;
- basename = g_file_get_basename (file);
- is_xpi = g_str_has_suffix (basename, ".xpi");
+ web_extensions_dir = g_file_new_build_filename (ephy_default_profile_dir (), "web_extensions", NULL);
+ is_xpi = g_str_has_suffix (g_file_peek_path (file), ".xpi");
/* FIXME: Make this async. */
- if (!is_xpi) {
- g_autoptr (GFile) source = NULL;
+ if (is_xpi) {
+ /* If we are given an .xpi file its a direct copy. */
+ basename = g_file_get_basename (file);
+ target = g_file_get_child (web_extensions_dir, basename);
- /* Get parent directory */
- source = g_file_get_parent (file);
- target = g_file_new_build_filename (ephy_default_profile_dir (), "web_extensions", g_file_get_basename
(source), NULL);
-
- ephy_copy_directory (g_file_get_path (source), g_file_get_path (target));
- } else {
- target = g_file_new_build_filename (ephy_default_profile_dir (), "web_extensions", g_file_get_basename
(file), NULL);
+ if (!g_file_make_directory_with_parents (web_extensions_dir, NULL, &error)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ g_warning ("Failed to create web_extensions directory: %s", error->message);
+ return;
+ }
+ g_clear_error (&error);
+ }
if (!g_file_copy (file, target, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
- g_warning ("Could not copy file for web_extensions: %s", error->message);
+ g_warning ("Could not copy file for web_extension: %s", error->message);
return;
}
+ g_clear_error (&error);
}
+ } else {
+ /* Otherwise we copy the parent directory. */
+ g_autoptr (GFile) parent = g_file_get_parent (file);
+ basename = g_file_get_basename (parent);
+ target = g_file_get_child (web_extensions_dir, basename);
+
+ ephy_copy_directory (g_file_peek_path (parent), g_file_peek_path (target));
}
if (target) {
diff --git a/src/webextension/ephy-web-extension.c b/src/webextension/ephy-web-extension.c
index 07ce43548..c88da11d8 100644
--- a/src/webextension/ephy-web-extension.c
+++ b/src/webextension/ephy-web-extension.c
@@ -926,7 +926,6 @@ load_directory_or_xpi_ready_cb (GFile *target,
GTask *load_task = user_data;
g_autoptr (GError) error = NULL;
g_autoptr (GHashTable) resources = NULL;
- g_autoptr (GFile) parent = NULL;
gboolean was_xpi = GPOINTER_TO_UINT (g_task_get_task_data (G_TASK (result)));
resources = g_task_propagate_pointer (G_TASK (result), &error);
@@ -935,11 +934,9 @@ load_directory_or_xpi_ready_cb (GFile *target,
return;
}
- parent = g_file_get_parent (target);
-
web_extension = g_object_new (EPHY_TYPE_WEB_EXTENSION, NULL);
web_extension->xpi = was_xpi;
- web_extension->base_location = g_file_get_path (parent);
+ web_extension->base_location = g_file_get_path (target);
web_extension->resources = g_steal_pointer (&resources);
if (!ephy_web_extension_parse_manifest (web_extension, &error)) {
@@ -1145,7 +1142,9 @@ ephy_web_extension_remove (EphyWebExtension *self)
if (!ephy_file_delete_dir_recursively (self->base_location, &error))
g_warning ("Could not delete web_extension from %s: %s", self->base_location, error->message);
} else {
- g_unlink (self->base_location);
+ g_autoptr (GFile) file = g_file_new_for_path (self->base_location);
+ if (!g_file_delete (file, NULL, &error))
+ g_warning ("Could not delete web_extension %s: %s", self->base_location, error->message);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]