[gcab] Find the file using the extracted name in gcab_folder_get_file_by_name()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcab] Find the file using the extracted name in gcab_folder_get_file_by_name()
- Date: Fri, 15 Dec 2017 22:24:46 +0000 (UTC)
commit 4b39ee675d67b0676dcc4005363a240636a8fbfc
Author: Richard Hughes <richard hughsie com>
Date: Fri Dec 15 22:11:58 2017 +0000
Find the file using the extracted name in gcab_folder_get_file_by_name()
libgcab/gcab-folder.c | 20 +++++++++++++++++++-
tests/gcab-self-test.c | 6 ++++++
2 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/libgcab/gcab-folder.c b/libgcab/gcab-folder.c
index d9917bd..146bb2e 100644
--- a/libgcab/gcab-folder.c
+++ b/libgcab/gcab-folder.c
@@ -378,9 +378,27 @@ gcab_folder_get_files (GCabFolder *self)
GCabFile *
gcab_folder_get_file_by_name (GCabFolder *self, const gchar *name)
{
+ GCabFile *cabfile;
+
g_return_val_if_fail (GCAB_IS_FOLDER (self), NULL);
g_return_val_if_fail (name != NULL, NULL);
- return g_hash_table_lookup (self->hash, name);
+
+ /* try the hash first */
+ cabfile = g_hash_table_lookup (self->hash, name);
+ if (cabfile != NULL)
+ return cabfile;
+
+ /* if the extract name is different, look for that too */
+ for (GSList *l = self->files; l != NULL; l = l->next) {
+ cabfile = GCAB_FILE (l->data);
+ if (gcab_file_get_name (cabfile) != gcab_file_get_extract_name (cabfile)) {
+ if (g_strcmp0 (gcab_file_get_extract_name (cabfile), name) == 0)
+ return cabfile;
+ }
+ }
+
+ /* nothing found */
+ return NULL;
}
static gint
diff --git a/tests/gcab-self-test.c b/tests/gcab-self-test.c
index 085ca2b..bfe3199 100644
--- a/tests/gcab-self-test.c
+++ b/tests/gcab-self-test.c
@@ -126,6 +126,12 @@ gcab_test_folder_func (void)
g_assert_nonnull (cabfile_tmp);
cabfile_tmp = gcab_folder_get_file_by_name (cabfolder, "notgoingtoexist");
g_assert_null (cabfile_tmp);
+
+ /* find the extracted name too */
+ cabfile_tmp = gcab_folder_get_file_by_name (cabfolder, "test.bin");
+ gcab_file_set_extract_name (cabfile_tmp, "LVFS-test.bin");
+ cabfile_tmp = gcab_folder_get_file_by_name (cabfolder, "LVFS-test.bin");
+ g_assert_nonnull (cabfile_tmp);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]