Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:AZhou:branches:GNOME:STABLE:3.34
tracker-miners
tracker-miners-CVE-2023-5557.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File tracker-miners-CVE-2023-5557.patch of Package tracker-miners
diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/config-miners.h.meson.in tracker-miners-2.3.3.new/config-miners.h.meson.in --- tracker-miners-2.3.3.old/config-miners.h.meson.in 2020-03-10 05:54:32.592932000 +0800 +++ tracker-miners-2.3.3.new/config-miners.h.meson.in 2023-12-08 15:11:34.505259700 +0800 @@ -87,6 +87,9 @@ /* Define to 0 if tracker FTS is not compiled */ #mesondefine HAVE_TRACKER_FTS +/* Define to 1 if you have the `memfd_create' function. */ +#mesondefine HAVE_MEMFD_CREATE + /* Define if we have UPOWER */ #mesondefine HAVE_UPOWER diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/meson.build tracker-miners-2.3.3.new/meson.build --- tracker-miners-2.3.3.old/meson.build 2020-03-10 05:54:32.597932000 +0800 +++ tracker-miners-2.3.3.new/meson.build 2023-12-08 15:11:34.508593052 +0800 @@ -340,6 +340,7 @@ conf.set('HAVE_POSIX_FADVISE', cc.has_function('posix_fadvise', prefix : '#include <fcntl.h>')) conf.set('HAVE_STATVFS64', cc.has_header_symbol('sys/statvfs.h', 'statvfs64', args: '-D_LARGEFILE64_SOURCE')) conf.set('HAVE_STRNLEN', cc.has_function('strnlen', prefix : '#include <string.h>')) +conf.set('HAVE_MEMFD_CREATE', cc.has_function('memfd_create', prefix : '#define _GNU_SOURCE\n#include <sys/mman.h>')) conf.set('LOCALEDIR', '"@0@/@1@"'.format(get_option('prefix'), get_option('localedir'))) conf.set('SHAREDIR', '"@0@/@1@"'.format(get_option('prefix'), get_option('datadir'))) diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/libtracker-extract/tracker-extract-info.c tracker-miners-2.3.3.new/src/libtracker-extract/tracker-extract-info.c --- tracker-miners-2.3.3.old/src/libtracker-extract/tracker-extract-info.c 2020-03-10 05:54:32.648933200 +0800 +++ tracker-miners-2.3.3.new/src/libtracker-extract/tracker-extract-info.c 2023-12-08 15:11:34.508593052 +0800 @@ -44,6 +44,8 @@ GFile *file; gchar *mimetype; + gint max_text; + gint ref_count; }; @@ -64,7 +66,8 @@ **/ TrackerExtractInfo * tracker_extract_info_new (GFile *file, - const gchar *mimetype) + const gchar *mimetype, + gint max_text) { TrackerExtractInfo *info; @@ -73,6 +76,7 @@ info = g_slice_new0 (TrackerExtractInfo); info->file = g_object_ref (file); info->mimetype = g_strdup (mimetype); + info->max_text = max_text; info->resource = NULL; @@ -220,3 +224,9 @@ g_object_ref (resource); info->resource = resource; } + +gint +tracker_extract_info_get_max_text (TrackerExtractInfo *info) +{ + return info->max_text; +} diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/libtracker-extract/tracker-extract-info.h tracker-miners-2.3.3.new/src/libtracker-extract/tracker-extract-info.h --- tracker-miners-2.3.3.old/src/libtracker-extract/tracker-extract-info.h 2020-03-10 05:54:32.648933200 +0800 +++ tracker-miners-2.3.3.new/src/libtracker-extract/tracker-extract-info.h 2023-12-08 15:11:34.508593052 +0800 @@ -36,12 +36,15 @@ GType tracker_extract_info_get_type (void) G_GNUC_CONST; TrackerExtractInfo * tracker_extract_info_new (GFile *file, - const gchar *mimetype); + const gchar *mimetype, + gint max_text); TrackerExtractInfo * tracker_extract_info_ref (TrackerExtractInfo *info); void tracker_extract_info_unref (TrackerExtractInfo *info); GFile * tracker_extract_info_get_file (TrackerExtractInfo *info); const gchar * tracker_extract_info_get_mimetype (TrackerExtractInfo *info); +gint tracker_extract_info_get_max_text (TrackerExtractInfo *info); + TrackerResource * tracker_extract_info_get_resource (TrackerExtractInfo *info); void tracker_extract_info_set_resource (TrackerExtractInfo *info, TrackerResource *resource); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/libtracker-miners-common/tracker-domain-ontology.c tracker-miners-2.3.3.new/src/libtracker-miners-common/tracker-domain-ontology.c --- tracker-miners-2.3.3.old/src/libtracker-miners-common/tracker-domain-ontology.c 2020-03-10 05:54:32.651933200 +0800 +++ tracker-miners-2.3.3.new/src/libtracker-miners-common/tracker-domain-ontology.c 2023-12-08 16:41:48.799916974 +0800 @@ -21,9 +21,44 @@ #include "config-miners.h" -#include <gio/gio.h> +#include <string.h> #include "tracker-domain-ontology.h" +struct _TrackerDomainOntology { + gint ref_count; + /* DomainOntologies section */ + GFile *cache_location; + GFile *journal_location; + GFile *ontology_location; + gchar *name; + gchar *domain; + gchar *ontology_name; + gchar **miners; +}; + +struct { + const gchar *var; + const gchar *(*func) (void); +} lookup_dirs[] = { + { "HOME", g_get_home_dir }, + { "XDG_CACHE_HOME", g_get_user_cache_dir }, + { "XDG_DATA_HOME", g_get_user_data_dir }, + { "XDG_RUNTIME_DIR", g_get_user_runtime_dir }, +}; + +struct { + const gchar *var; + GUserDirectory user_directory; +} lookup_special_dirs[] = { + { "XDG_DESKTOP_DIR", G_USER_DIRECTORY_DESKTOP }, + { "XDG_DOCUMENTS_DIR", G_USER_DIRECTORY_DOCUMENTS }, + { "XDG_DOWNLOAD_DIR", G_USER_DIRECTORY_DOWNLOAD }, + { "XDG_MUSIC_DIR", G_USER_DIRECTORY_MUSIC }, + { "XDG_PICTURES_DIR", G_USER_DIRECTORY_PICTURES }, + { "XDG_PUBLICSHARE_DIR", G_USER_DIRECTORY_PUBLIC_SHARE }, + { "XDG_VIDEOS_DIR", G_USER_DIRECTORY_VIDEOS }, +}; + #define DOMAIN_ONTOLOGY_SECTION "DomainOntology" #define CACHE_KEY "CacheLocation" @@ -35,6 +70,125 @@ #define DEFAULT_RULE "default.rule" +TrackerDomainOntology * +tracker_domain_ontology_ref (TrackerDomainOntology *domain_ontology) +{ + domain_ontology->ref_count++; + return domain_ontology; +} + +void +tracker_domain_ontology_unref (TrackerDomainOntology *domain_ontology) +{ + domain_ontology->ref_count--; + + if (domain_ontology->ref_count != 0) + return; + + g_clear_object (&domain_ontology->cache_location); + g_clear_object (&domain_ontology->journal_location); + g_clear_object (&domain_ontology->ontology_location); + g_free (domain_ontology->ontology_name); + g_free (domain_ontology->name); + g_free (domain_ontology->domain); + g_strfreev (domain_ontology->miners); + g_free (domain_ontology); +} + +static const gchar * +lookup_dir (const gchar *variable, + gsize variable_len) +{ + gint i; + + for (i = 0; i < G_N_ELEMENTS (lookup_dirs); i++) { + if (strncmp (lookup_dirs[i].var, variable, variable_len) == 0) { + return lookup_dirs[i].func (); + } + } + + for (i = 0; i < G_N_ELEMENTS (lookup_special_dirs); i++) { + if (strncmp (lookup_special_dirs[i].var, variable, variable_len) == 0) { + return g_get_user_special_dir (lookup_special_dirs[i].user_directory); + } + } + + return NULL; +} + +static GFile * +key_file_get_location (GKeyFile *key_file, + const gchar *section, + const gchar *key, + gboolean essential, + gboolean must_exist, + GError **error) +{ + GError *inner_error = NULL; + gchar *value; + GFile *file; + + value = g_key_file_get_string (key_file, section, key, &inner_error); + if (inner_error) { + if (essential) + g_propagate_error (error, inner_error); + else + g_error_free (inner_error); + + return NULL; + } + + if (value[0] == '$') { + const gchar *var_end, *prefix; + gchar *path; + + /* This is a path relative from a xdg dir */ + var_end = strchr (value, '/'); + if (!var_end) { + /* We must take $VAR/subdir values */ + g_set_error (error, + G_KEY_FILE_ERROR, + G_KEY_FILE_ERROR_INVALID_VALUE, + "Path in key '%s' can not consist solely of a variable", + key); + g_free (value); + return NULL; + } + + prefix = lookup_dir (&value[1], (var_end - &value[1])); + if (!prefix) { + g_set_error (error, + G_KEY_FILE_ERROR, + G_KEY_FILE_ERROR_INVALID_VALUE, + "Unrecognized variable in '%s'", key); + g_free (value); + return NULL; + } + + path = g_strconcat (prefix, var_end, NULL); + file = g_file_new_for_path (path); + g_free (path); + } else { + file = g_file_new_for_uri (value); + } + + g_free (value); + + if (must_exist && file && + g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL) != G_FILE_TYPE_DIRECTORY) { + gchar *uri = g_file_get_uri (file); + g_set_error (error, + G_KEY_FILE_ERROR, + G_KEY_FILE_ERROR_INVALID_VALUE, + "Uri '%s' is not a directory or does not exist", uri); + g_free (uri); + return NULL; + } + + return file; +} + static gchar * find_rule_in_data_dirs (const gchar *name) { @@ -62,33 +216,38 @@ return NULL; } -gboolean -tracker_load_domain_config (const gchar *name, - gchar **dbus_domain_name, - GError **error) +TrackerDomainOntology * +tracker_domain_ontology_new (const gchar *domain_name, + GCancellable *cancellable, + GError **error) { - GKeyFile *key_file; - gchar *path, *path_for_tests; + TrackerDomainOntology *domain_ontology; GError *inner_error = NULL; + GKeyFile *key_file = NULL; + gchar *path, *path_for_tests; - if (name && name[0] == '/') { - if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { + domain_ontology = g_new0 (TrackerDomainOntology, 1); + domain_ontology->name = g_strdup (domain_name); + domain_ontology->ref_count = 1; + + if (domain_name && domain_name[0] == '/') { + if (!g_file_test (domain_name, G_FILE_TEST_IS_REGULAR)) { inner_error = g_error_new (G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND, "Could not find rule at '%s'", - name); + domain_name); goto end; } - path = g_strdup (name); - } else if (name) { - path = find_rule_in_data_dirs (name); + path = g_strdup (domain_name); + } else if (domain_name) { + path = find_rule_in_data_dirs (domain_name); if (!path) { inner_error = g_error_new (G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND, "Could not find rule '%s' in data dirs", - name); + domain_name); goto end; } } else { @@ -100,11 +259,7 @@ path_for_tests = g_strdup (g_getenv ("TRACKER_TEST_DOMAIN_ONTOLOGY_RULE")); if (path_for_tests == NULL) { - inner_error = g_error_new (G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_NOT_FOUND, - "Unable to find default domain ontology rule %s", - path); - goto end; + g_error ("Unable to find default domain ontology rule %s", path); } g_free (path); @@ -119,19 +274,122 @@ if (inner_error) goto end; - *dbus_domain_name = g_key_file_get_string (key_file, DOMAIN_ONTOLOGY_SECTION, - DOMAIN_KEY, &inner_error); + domain_ontology->domain = g_key_file_get_string (key_file, DOMAIN_ONTOLOGY_SECTION, + DOMAIN_KEY, &inner_error); + if (inner_error) + goto end; + + domain_ontology->cache_location = + key_file_get_location (key_file, DOMAIN_ONTOLOGY_SECTION, + CACHE_KEY, TRUE, FALSE, &inner_error); if (inner_error) goto end; + domain_ontology->journal_location = + key_file_get_location (key_file, DOMAIN_ONTOLOGY_SECTION, + JOURNAL_KEY, FALSE, FALSE, &inner_error); + if (inner_error) + goto end; + + domain_ontology->ontology_location = + key_file_get_location (key_file, DOMAIN_ONTOLOGY_SECTION, + ONTOLOGY_KEY, FALSE, TRUE, &inner_error); + if (inner_error) + goto end; + + domain_ontology->ontology_name = g_key_file_get_string (key_file, DOMAIN_ONTOLOGY_SECTION, + ONTOLOGY_NAME_KEY, NULL); + domain_ontology->miners = g_key_file_get_string_list (key_file, DOMAIN_ONTOLOGY_SECTION, + MINERS_KEY, NULL, NULL); + + /* Consistency check, we need one of OntologyLocation and OntologyName, + * no more, no less. + */ + if ((domain_ontology->ontology_name && domain_ontology->ontology_location) || + (!domain_ontology->ontology_name && !domain_ontology->ontology_location)) { + inner_error = g_error_new (G_KEY_FILE_ERROR, + G_KEY_FILE_ERROR_INVALID_VALUE, + "One of OntologyLocation and OntologyName must be provided"); + } + + /* Build ontology location from name if necessary */ + if (!domain_ontology->ontology_location) { + gchar *ontology_path; + + if (g_getenv ("TRACKER_DB_ONTOLOGIES_DIR") != NULL) { + /* Override for use only by testcases */ + domain_ontology->ontology_location = g_file_new_for_path (g_getenv ("TRACKER_DB_ONTOLOGIES_DIR")); + } else { + ontology_path = g_build_filename (SHAREDIR, "tracker", "ontologies", + domain_ontology->ontology_name, NULL); + + if (!g_file_test (ontology_path, G_FILE_TEST_IS_DIR)) { + g_error ("Unable to find ontologies in the configured location %s", ontology_path); + } + + domain_ontology->ontology_location = g_file_new_for_path (ontology_path); + + g_free (ontology_path); + } + } + end: if (key_file) g_key_file_free (key_file); if (inner_error) { g_propagate_error (error, inner_error); + tracker_domain_ontology_unref (domain_ontology); + return NULL; + } + + return domain_ontology; +} + +GFile * +tracker_domain_ontology_get_cache (TrackerDomainOntology *domain_ontology) +{ + return domain_ontology->cache_location; +} + +GFile * +tracker_domain_ontology_get_journal (TrackerDomainOntology *domain_ontology) +{ + return domain_ontology->journal_location; +} + +GFile * +tracker_domain_ontology_get_ontology (TrackerDomainOntology *domain_ontology) +{ + return domain_ontology->ontology_location; +} + +gchar * +tracker_domain_ontology_get_domain (TrackerDomainOntology *domain_ontology, + const gchar *suffix) +{ + if (suffix) + return g_strconcat (domain_ontology->domain, ".", suffix, NULL); + else + return g_strconcat (domain_ontology->domain, NULL); +} + +gboolean +tracker_domain_ontology_uses_miner (TrackerDomainOntology *domain_ontology, + const gchar *suffix) +{ + guint i; + + g_return_val_if_fail (suffix != NULL, FALSE); + + if (!domain_ontology->miners) return FALSE; + + for (i = 0; domain_ontology->miners[i] != NULL; i++) { + if (strcmp (domain_ontology->miners[i], suffix) == 0) { + return TRUE; + } } - return TRUE; + return FALSE; } diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/libtracker-miners-common/tracker-domain-ontology.h tracker-miners-2.3.3.new/src/libtracker-miners-common/tracker-domain-ontology.h --- tracker-miners-2.3.3.old/src/libtracker-miners-common/tracker-domain-ontology.h 2020-03-10 05:54:32.651933200 +0800 +++ tracker-miners-2.3.3.new/src/libtracker-miners-common/tracker-domain-ontology.h 2023-12-08 16:42:19.656548721 +0800 @@ -27,7 +27,25 @@ #endif #include <glib-object.h> +#include <gio/gio.h> -gboolean tracker_load_domain_config (const gchar *name, gchar **dbus_domain_name, GError **error); +typedef struct _TrackerDomainOntology TrackerDomainOntology; + +TrackerDomainOntology * tracker_domain_ontology_new (const gchar *name, + GCancellable *cancellable, + GError **error); +TrackerDomainOntology * tracker_domain_ontology_ref (TrackerDomainOntology *domain_ontology); + +void tracker_domain_ontology_unref (TrackerDomainOntology *domain_ontology); + +GFile * tracker_domain_ontology_get_cache (TrackerDomainOntology *domain_ontology); +GFile * tracker_domain_ontology_get_journal (TrackerDomainOntology *domain_ontology); +GFile * tracker_domain_ontology_get_ontology (TrackerDomainOntology *domain_ontology); + +gchar * tracker_domain_ontology_get_domain (TrackerDomainOntology *domain_ontology, + const gchar *suffix); + +gboolean tracker_domain_ontology_uses_miner (TrackerDomainOntology *domain_ontology, + const gchar *suffix); #endif /* __TRACKER_DOMAIN_ONTOLOGY_H__ */ diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/libtracker-miners-common/tracker-seccomp.c tracker-miners-2.3.3.new/src/libtracker-miners-common/tracker-seccomp.c --- tracker-miners-2.3.3.old/src/libtracker-miners-common/tracker-seccomp.c 2020-03-10 05:54:32.653933300 +0800 +++ tracker-miners-2.3.3.new/src/libtracker-miners-common/tracker-seccomp.c 2023-12-08 15:36:29.102433291 +0800 @@ -63,12 +63,15 @@ /* Memory management */ ALLOW_RULE (brk); + ALLOW_RULE (get_mempolicy); + ALLOW_RULE (set_mempolicy); ALLOW_RULE (mmap); ALLOW_RULE (mmap2); ALLOW_RULE (munmap); ALLOW_RULE (mremap); ALLOW_RULE (mprotect); ALLOW_RULE (madvise); + ALLOW_RULE (mbind); ERROR_RULE (mlock, EPERM); ERROR_RULE (mlock2, EPERM); ERROR_RULE (munlock, EPERM); @@ -77,6 +80,7 @@ /* Process management */ ALLOW_RULE (exit_group); ALLOW_RULE (getuid); + ALLOW_RULE (getgid); ALLOW_RULE (getuid32); ALLOW_RULE (getegid); ALLOW_RULE (getegid32); @@ -97,19 +101,24 @@ ALLOW_RULE (statfs64); ALLOW_RULE (lstat); ALLOW_RULE (lstat64); + ALLOW_RULE (statx); + ALLOW_RULE (fstatfs); ALLOW_RULE (access); ALLOW_RULE (getdents); ALLOW_RULE (getdents64); + ALLOW_RULE (getcwd); ALLOW_RULE (readlink); ALLOW_RULE (readlinkat); ALLOW_RULE (utime); ALLOW_RULE (time); ALLOW_RULE (fsync); ALLOW_RULE (umask); + ERROR_RULE (fchown, EPERM); /* Processes and threads */ ALLOW_RULE (clone); ALLOW_RULE (futex); ALLOW_RULE (set_robust_list); + ALLOW_RULE (rseq); ALLOW_RULE (rt_sigaction); ALLOW_RULE (rt_sigprocmask); ALLOW_RULE (sched_yield); @@ -129,6 +138,11 @@ ALLOW_RULE (eventfd2); ALLOW_RULE (pipe); ALLOW_RULE (pipe2); + ALLOW_RULE (pipe); + ALLOW_RULE (pipe2); + ALLOW_RULE (epoll_create); + ALLOW_RULE (epoll_create1); + ALLOW_RULE (epoll_ctl); /* System */ ALLOW_RULE (uname); ALLOW_RULE (sysinfo); @@ -165,6 +179,22 @@ ALLOW_RULE (getpeername); ALLOW_RULE (shutdown); + ERROR_RULE (inotify_init1, EINVAL); + ERROR_RULE (inotify_init, EINVAL); + + ERROR_RULE (mkdir, EPERM); + ERROR_RULE (rename, EPERM); + ERROR_RULE (unlink, EPERM); + ERROR_RULE (ioctl, EBADF); + ERROR_RULE (bind, EACCES); + ERROR_RULE (setsockopt, EBADF); + ERROR_RULE (sched_getattr, EPERM); + + /* Allow prlimit64, only if no new limits are being set */ + if (seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS(prlimit64), 1, + SCMP_CMP(2, SCMP_CMP_EQ, 0)) < 0) + goto out; + /* Special requirements for socket/socketpair, only on AF_UNIX/AF_LOCAL */ if (seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_UNIX)) < 0) @@ -172,6 +202,9 @@ if (seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_LOCAL)) < 0) goto out; + if (seccomp_rule_add (ctx, SCMP_ACT_ERRNO (EACCES), SCMP_SYS(socket), 1, + SCMP_CMP(0, SCMP_CMP_EQ, AF_NETLINK)) < 0) + goto out; if (seccomp_rule_add (ctx, SCMP_ACT_ALLOW, SCMP_SYS(socketpair), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_UNIX)) < 0) goto out; diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/fs/meson.build tracker-miners-2.3.3.new/src/miners/fs/meson.build --- tracker-miners-2.3.3.old/src/miners/fs/meson.build 2020-03-10 05:54:32.654933200 +0800 +++ tracker-miners-2.3.3.new/src/miners/fs/meson.build 2023-12-08 15:11:34.508593052 +0800 @@ -1,6 +1,7 @@ sources = [ 'tracker-config.c', 'tracker-extract-watchdog.c', + 'tracker-files-interface.c', 'tracker-main.c', 'tracker-miner-files.c', 'tracker-miner-files-index.c', diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/fs/tracker-files-interface.c tracker-miners-2.3.3.new/src/miners/fs/tracker-files-interface.c --- tracker-miners-2.3.3.old/src/miners/fs/tracker-files-interface.c 1970-01-01 08:00:00.000000000 +0800 +++ tracker-miners-2.3.3.new/src/miners/fs/tracker-files-interface.c 2023-12-08 15:25:06.947584804 +0800 @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2023 Red Hat Inc. + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * Author: Carlos Garnacho <carlosg@gnome.org> + */ + +#include "config-miners.h" + +#include "tracker-files-interface.h" + +#include <gio/gunixfdlist.h> +#include <sys/mman.h> + +struct _TrackerFilesInterface +{ + GObject parent_instance; + GDBusConnection *connection; + GSettings *settings; + guint object_id; + int fd; +}; + +enum { + PROP_0, + PROP_CONNECTION, + N_PROPS, +}; + +static GParamSpec *props[N_PROPS] = { 0, }; + +static const gchar *introspection_xml = + "<node>" + " <interface name='org.freedesktop.Tracker1.Files'>" + " <property name='ExtractorConfig' type='a{sv}' access='read' />" + " <method name='GetPersistenceStorage'>" + " <arg type='h' direction='out' />" + " </method>" + " </interface>" + "</node>"; + +G_DEFINE_TYPE (TrackerFilesInterface, tracker_files_interface, G_TYPE_OBJECT) + +static void +tracker_files_interface_init (TrackerFilesInterface *files_interface) +{ +} + +static void +handle_method_call (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + TrackerFilesInterface *files_interface = user_data; + + if (g_strcmp0 (method_name, "GetPersistenceStorage") == 0) { + GVariant *out_parameters; + g_autoptr (GUnixFDList) fd_list = NULL; + g_autoptr (GError) error = NULL; + int idx; + + if (files_interface->fd <= 0) { +#ifdef HAVE_MEMFD_CREATE + files_interface->fd = memfd_create ("extract-persistent-storage", + MFD_CLOEXEC); +#else + g_autofree gchar *path = NULL; + + path = g_strdup_printf ("%s/tracker-persistence.XXXXXX", + g_get_tmp_dir ()); + files_interface->fd = g_mkstemp_full (path, 0, 0600); + unlink (path); +#endif + + if (files_interface->fd < 0) { + g_dbus_method_invocation_return_error (invocation, + G_IO_ERROR, + G_IO_ERROR_FAILED, + "Could not create memfd"); + return; + } + } + + fd_list = g_unix_fd_list_new (); + idx = g_unix_fd_list_append (fd_list, files_interface->fd, &error); + + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + } else { + out_parameters = g_variant_new ("(h)", idx); + g_dbus_method_invocation_return_value_with_unix_fd_list (invocation, + out_parameters, + fd_list); + } + } else { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_UNKNOWN_METHOD, + "Unknown method %s", + method_name); + } +} + +static GVariant * +handle_get_property (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error, + gpointer user_data) +{ + TrackerFilesInterface *files_interface = user_data; + + if (g_strcmp0 (object_path, "/org/freedesktop/Tracker1/Miner/Files") != 0 || + g_strcmp0 (interface_name, "org.freedesktop.Tracker1.Miner.Files") != 0) { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, + "Wrong object/interface"); + return NULL; + } + + if (g_strcmp0 (property_name, "ExtractorConfig") == 0) { + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&builder, "{sv}", "max-bytes", + g_settings_get_value (files_interface->settings, "max-bytes")); + + return g_variant_builder_end (&builder); + } else { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, + "Unknown property"); + return NULL; + } +} + +static void +tracker_files_interface_constructed (GObject *object) +{ + TrackerFilesInterface *files_interface = TRACKER_FILES_INTERFACE (object); + GDBusInterfaceVTable vtable = { handle_method_call, handle_get_property, NULL }; + g_autoptr (GDBusNodeInfo) introspection_data = NULL; + + G_OBJECT_CLASS (tracker_files_interface_parent_class)->constructed (object); + + introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); + files_interface->object_id = + g_dbus_connection_register_object (files_interface->connection, + "/org/freedesktop/Tracker1/Files", + introspection_data->interfaces[0], + &vtable, object, NULL, NULL); + + files_interface->settings = g_settings_new ("org.freedesktop.Tracker.Extract"); +} + +static void +tracker_files_interface_finalize (GObject *object) +{ + TrackerFilesInterface *files_interface = TRACKER_FILES_INTERFACE (object); + + g_dbus_connection_unregister_object (files_interface->connection, + files_interface->object_id); + g_clear_object (&files_interface->connection); + g_clear_object (&files_interface->settings); + + if (files_interface->fd) + close (files_interface->fd); + + G_OBJECT_CLASS (tracker_files_interface_parent_class)->finalize (object); +} + +static void +tracker_files_interface_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + TrackerFilesInterface *files_interface = TRACKER_FILES_INTERFACE (object); + + switch (prop_id) { + case PROP_CONNECTION: + files_interface->connection = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +tracker_files_interface_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TrackerFilesInterface *files_interface = TRACKER_FILES_INTERFACE (object); + + switch (prop_id) { + case PROP_CONNECTION: + g_value_set_object (value, files_interface->connection); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +tracker_files_interface_class_init (TrackerFilesInterfaceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = tracker_files_interface_constructed; + object_class->finalize = tracker_files_interface_finalize; + object_class->set_property = tracker_files_interface_set_property; + object_class->get_property = tracker_files_interface_get_property; + + props[PROP_CONNECTION] = + g_param_spec_object ("connection", + NULL, NULL, + G_TYPE_DBUS_CONNECTION, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, N_PROPS, props); +} + +TrackerFilesInterface * +tracker_files_interface_new (GDBusConnection *connection) +{ + return g_object_new (TRACKER_TYPE_FILES_INTERFACE, + "connection", connection, + NULL); +} diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/fs/tracker-files-interface.h tracker-miners-2.3.3.new/src/miners/fs/tracker-files-interface.h --- tracker-miners-2.3.3.old/src/miners/fs/tracker-files-interface.h 1970-01-01 08:00:00.000000000 +0800 +++ tracker-miners-2.3.3.new/src/miners/fs/tracker-files-interface.h 2023-12-08 15:11:34.508593052 +0800 @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2023 Red Hat Inc. + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * Author: Carlos Garnacho <carlosg@gnome.org> + */ + +#ifndef __TRACKER_FILES_INTERFACE_H__ +#define __TRACKER_FILES_INTERFACE_H__ + +#include <gio/gio.h> + +#define TRACKER_TYPE_FILES_INTERFACE (tracker_files_interface_get_type ()) +G_DECLARE_FINAL_TYPE (TrackerFilesInterface, + tracker_files_interface, + TRACKER, FILES_INTERFACE, + GObject) + +TrackerFilesInterface * tracker_files_interface_new (GDBusConnection *connection); + +#endif /* __TRACKER_FILES_INTERFACE_H__ */ diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/fs/tracker-main.c tracker-miners-2.3.3.new/src/miners/fs/tracker-main.c --- tracker-miners-2.3.3.old/src/miners/fs/tracker-main.c 2020-03-10 05:54:32.655933400 +0800 +++ tracker-miners-2.3.3.new/src/miners/fs/tracker-main.c 2023-12-08 23:20:06.426927527 +0800 @@ -38,6 +38,7 @@ #include "tracker-config.h" #include "tracker-miner-files.h" #include "tracker-miner-files-index.h" +#include "tracker-files-interface.h" #include "tracker-writeback.h" #define ABOUT \ @@ -756,6 +757,40 @@ g_main_loop_quit (loop); } +static gboolean +setup_connection_and_endpoint (TrackerDomainOntology *domain, + GDBusConnection *connection, + TrackerSparqlConnection **sparql_conn, + TrackerEndpointDBus **endpoint, + GError **error) +{ + GFile *cache, *store, *ontology; + + cache = tracker_domain_ontology_get_cache (domain); + store = g_file_get_child (cache, "files"); + ontology = tracker_domain_ontology_get_ontology (domain); + *sparql_conn = tracker_sparql_connection_local_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE, + store, + NULL, + ontology, + NULL, + error); + g_clear_object (&store); + + if (!*sparql_conn) + return FALSE; + + *endpoint = tracker_endpoint_dbus_new (*sparql_conn, + connection, + NULL, + NULL, + error); + if (!*endpoint) + return FALSE; + + return TRUE; +} + int main (gint argc, gchar *argv[]) { @@ -770,7 +805,11 @@ gboolean store_available; TrackerMinerProxy *proxy; GDBusConnection *connection; - gchar *dbus_domain_name, *dbus_name; + TrackerSparqlConnection *sparql_conn; + TrackerEndpointDBus *endpoint; + TrackerDomainOntology *domain_ontology; + gchar *domain_name, *dbus_name; + TrackerFilesInterface *files_interface; main_loop = NULL; @@ -810,7 +849,7 @@ tracker_sparql_connection_set_domain (domain_ontology_name); - tracker_load_domain_config (domain_ontology_name, &dbus_domain_name, &error); + domain_ontology = tracker_domain_ontology_new (domain_ontology_name, NULL, &error); if (error != NULL) { g_critical ("Could not load domain ontology '%s': %s", @@ -830,6 +869,8 @@ return EXIT_FAILURE; } + files_interface = tracker_files_interface_new (connection); + /* Initialize logging */ config = tracker_config_new (); @@ -852,16 +893,18 @@ main_loop = g_main_loop_new (NULL, FALSE); - if (domain_ontology_name) { + if (domain_ontology && domain_ontology_name) { /* If we are running for a specific domain, we tie the lifetime of this * process to the domain. For example, if the domain name is * org.example.MyApp then this tracker-miner-fs process will exit as * soon as org.example.MyApp exits. */ - g_bus_watch_name_on_connection (connection, dbus_domain_name, + domain_name = tracker_domain_ontology_get_domain (domain_ontology, NULL); + g_bus_watch_name_on_connection (connection, domain_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, on_domain_vanished, main_loop, NULL); + g_free (domain_name); } g_message ("Checking if we're running as a daemon:"); @@ -869,8 +912,21 @@ no_daemon ? "No" : "Yes", no_daemon ? "(forced by command line)" : ""); + if (!setup_connection_and_endpoint (domain_ontology, + connection, + &sparql_conn, + &endpoint, + &error)) { + + g_critical ("Could not create store/endpoint: %s", + error->message); + g_error_free (error); + + return EXIT_FAILURE; + } + /* Create new TrackerMinerFiles object */ - miner_files = tracker_miner_files_new (config, &error); + miner_files = tracker_miner_files_new (sparql_conn, config, &error); if (!miner_files) { g_critical ("Couldn't create new Files miner: '%s'", error ? error->message : "unknown error"); @@ -916,7 +972,7 @@ } /* Request DBus name */ - dbus_name = g_strconcat (dbus_domain_name, ".", DBUS_NAME_SUFFIX, NULL); + dbus_name = tracker_domain_ontology_get_domain (domain_ontology, DBUS_NAME_SUFFIX); if (!tracker_dbus_request_name (connection, dbus_name, &error)) { g_critical ("Could not request DBus name '%s': %s", @@ -982,6 +1038,8 @@ save_current_locale (); } + g_object_unref (files_interface); + g_main_loop_unref (main_loop); g_object_unref (config); g_object_unref (miner_files_index); @@ -991,7 +1049,9 @@ g_object_unref (proxy); g_object_unref (connection); - g_free (dbus_domain_name); + tracker_domain_ontology_unref (domain_ontology); + + g_object_unref (sparql_conn); tracker_writeback_shutdown (); tracker_log_shutdown (); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/fs/tracker-miner-files.c tracker-miners-2.3.3.new/src/miners/fs/tracker-miner-files.c --- tracker-miners-2.3.3.old/src/miners/fs/tracker-miner-files.c 2020-03-10 05:54:32.656933300 +0800 +++ tracker-miners-2.3.3.new/src/miners/fs/tracker-miner-files.c 2023-12-08 16:32:13.164897742 +0800 @@ -2837,12 +2837,14 @@ } TrackerMiner * -tracker_miner_files_new (TrackerConfig *config, - GError **error) +tracker_miner_files_new (TrackerSparqlConnection *connection, + TrackerConfig *config, + GError **error) { return g_initable_new (TRACKER_TYPE_MINER_FILES, NULL, error, + "connection", connection, "root", NULL, "config", config, "processing-pool-wait-limit", 10, diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/fs/tracker-miner-files.h tracker-miners-2.3.3.new/src/miners/fs/tracker-miner-files.h --- tracker-miners-2.3.3.old/src/miners/fs/tracker-miner-files.h 2020-03-10 05:54:32.656933300 +0800 +++ tracker-miners-2.3.3.new/src/miners/fs/tracker-miner-files.h 2023-12-08 16:33:40.708693099 +0800 @@ -48,8 +48,9 @@ GType tracker_miner_files_get_type (void) G_GNUC_CONST; -TrackerMiner *tracker_miner_files_new (TrackerConfig *config, - GError **error); +TrackerMiner *tracker_miner_files_new (TrackerSparqlConnection *connection, + TrackerConfig *config, + GError **error); /* Convenience functions for --eligible tracker-miner-fs cmdline */ gboolean tracker_miner_files_check_file (GFile *file, diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/rss/tracker-main.c tracker-miners-2.3.3.new/src/miners/rss/tracker-main.c --- tracker-miners-2.3.3.old/src/miners/rss/tracker-main.c 2020-03-10 05:54:32.659933300 +0800 +++ tracker-miners-2.3.3.new/src/miners/rss/tracker-main.c 2023-12-08 22:29:14.590139079 +0800 @@ -68,6 +68,41 @@ g_main_loop_quit (loop); } +static gboolean +setup_connection_and_endpoint (TrackerDomainOntology *domain, + GDBusConnection *connection, + TrackerSparqlConnection **sparql_conn, + TrackerEndpointDBus **endpoint, + GError **error) +{ + GFile *cache, *store, *ontology; + + cache = tracker_domain_ontology_get_cache (domain); + store = g_file_get_child (cache, "rss"); + ontology = tracker_domain_ontology_get_ontology (domain); + *sparql_conn = tracker_sparql_connection_local_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE, + store, + NULL, + ontology, + NULL, + error); + g_object_unref (store); + g_object_unref (ontology); + + if (!*sparql_conn) + return FALSE; + + *endpoint = tracker_endpoint_dbus_new (*sparql_conn, + connection, + NULL, + NULL, + error); + if (!*endpoint) + return FALSE; + + return TRUE; +} + int main (int argc, char **argv) { @@ -77,8 +112,10 @@ TrackerMinerRSS *miner; GError *error = NULL; GDBusConnection *connection; + TrackerSparqlConnection *sparql_conn; TrackerMinerProxy *proxy; - gchar *dbus_domain_name, *dbus_name; + TrackerDomainOntology *domain_ontology; + gchar *domain_name, *dbus_name; setlocale (LC_ALL, ""); @@ -120,7 +157,8 @@ title, add_feed); - connection = tracker_sparql_connection_get (NULL, &error); + connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker1.Miner.RSS", + NULL, NULL, &error); if (!connection) { g_printerr ("%s: %s\n", @@ -171,7 +209,7 @@ g_free (log_filename); } - tracker_load_domain_config (domain_ontology_name, &dbus_domain_name, &error); + domain_ontology = tracker_domain_ontology_new (domain_ontology_name, NULL, &error); if (error) { g_critical ("Could not load domain ontology '%s': %s", @@ -188,7 +226,20 @@ return EXIT_FAILURE; } - miner = tracker_miner_rss_new (&error); + if (!setup_connection_and_endpoint (domain_ontology, + connection, + &sparql_conn, + &endpoint, + &error)) { + + g_critical ("Could not create store/endpoint: %s", + error->message); + g_error_free (error); + + return EXIT_FAILURE; + } + + miner = tracker_miner_rss_new (sparql_conn, &error); if (!miner) { g_critical ("Could not create new RSS miner: '%s', exiting...\n", error ? error->message : "unknown error"); @@ -203,7 +254,7 @@ return EXIT_FAILURE; } - dbus_name = g_strconcat (dbus_domain_name, ".", DBUS_NAME_SUFFIX, NULL); + dbus_name = tracker_domain_ontology_get_domain (domain_ontology, DBUS_NAME_SUFFIX); if (!tracker_dbus_request_name (connection, dbus_name, &error)) { g_critical ("Could not request DBus name '%s': %s", @@ -217,26 +268,29 @@ loop = g_main_loop_new (NULL, FALSE); - if (domain_ontology_name) { + if (domain_ontology && domain_ontology_name) { /* If we are running for a specific domain, we tie the lifetime of this * process to the domain. For example, if the domain name is * org.example.MyApp then this tracker-miner-rss process will exit as * soon as org.example.MyApp exits. */ - g_bus_watch_name_on_connection (connection, dbus_domain_name, + domain_name = tracker_domain_ontology_get_domain (domain_ontology, NULL); + g_bus_watch_name_on_connection (connection, domain_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, on_domain_vanished, loop, NULL); + g_free (domain_name); } g_main_loop_run (loop); tracker_log_shutdown (); g_main_loop_unref (loop); + g_object_unref (sparql_conn); g_object_unref (miner); g_object_unref (connection); g_object_unref (proxy); - g_free (dbus_domain_name); + tracker_domain_ontology_unref (domain_ontology); return EXIT_SUCCESS; } diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/rss/tracker-miner-rss.c tracker-miners-2.3.3.new/src/miners/rss/tracker-miner-rss.c --- tracker-miners-2.3.3.old/src/miners/rss/tracker-miner-rss.c 2020-03-10 05:54:32.659933300 +0800 +++ tracker-miners-2.3.3.new/src/miners/rss/tracker-miner-rss.c 2023-12-08 16:53:08.417431080 +0800 @@ -246,7 +246,8 @@ { GError *error = NULL; TrackerMinerRSSPrivate *priv; - gchar *dbus_domain_name; + TrackerDomainOntology *domain_ontology; + gchar *dbus_name; g_message ("Initializing..."); @@ -277,11 +278,13 @@ g_message ("Listening for GraphUpdated changes on D-Bus interface..."); g_message (" arg0:'%s'", TRACKER_PREFIX_MFO "FeedChannel"); - tracker_load_domain_config (tracker_sparql_connection_get_domain (), &dbus_domain_name, &error); + domain_ontology = tracker_domain_ontology_new (tracker_sparql_connection_get_domain (), + NULL, NULL); + dbus_name = tracker_domain_ontology_get_domain (domain_ontology, NULL); priv->graph_updated_id = g_dbus_connection_signal_subscribe (priv->connection, - dbus_domain_name, + dbus_name, "org.freedesktop.Tracker1.Resources", "GraphUpdated", "/org/freedesktop/Tracker1/Resources", @@ -291,7 +294,7 @@ object, NULL); - g_free (dbus_domain_name); + tracker_domain_ontology_unref (domain_ontology); } static void @@ -1309,7 +1312,8 @@ } TrackerMinerRSS * -tracker_miner_rss_new (GError **error) +tracker_miner_rss_new (TrackerSparqlConnection *connection, + GError **error) { return g_initable_new (TRACKER_TYPE_MINER_RSS, NULL, diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/miners/rss/tracker-miner-rss.h tracker-miners-2.3.3.new/src/miners/rss/tracker-miner-rss.h --- tracker-miners-2.3.3.old/src/miners/rss/tracker-miner-rss.h 2020-03-10 05:54:32.659933300 +0800 +++ tracker-miners-2.3.3.new/src/miners/rss/tracker-miner-rss.h 2023-12-08 16:53:20.144131833 +0800 @@ -46,7 +46,8 @@ }; GType tracker_miner_rss_get_type (void) G_GNUC_CONST; -TrackerMinerRSS *tracker_miner_rss_new (GError **error); +TrackerMinerRSS *tracker_miner_rss_new (TrackerSparqlConnection *conn, + GError **error); G_END_DECLS diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/meson.build tracker-miners-2.3.3.new/src/tracker-extract/meson.build --- tracker-miners-2.3.3.old/src/tracker-extract/meson.build 2020-03-10 05:54:32.662933300 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/meson.build 2023-12-08 15:11:34.508593052 +0800 @@ -141,7 +141,6 @@ namespace: 'TrackerExtractDBus') tracker_extract_sources = [ - 'tracker-config.c', 'tracker-extract.c', 'tracker-extract-controller.c', 'tracker-extract-decorator.c', diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-config.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-config.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-config.c 2020-03-10 05:54:32.662933300 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-config.c 1970-01-01 08:00:00.000000000 +0800 @@ -1,304 +0,0 @@ -/* - * Copyright (C) 2009, Nokia <ivan.frade@nokia.com> - * Copyright (C) 2014, Lanedo <martyn@lanedo.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config-miners.h" - -#define G_SETTINGS_ENABLE_BACKEND -#include <gio/gsettingsbackend.h> - -#include <libtracker-miners-common/tracker-common.h> - -#include "tracker-config.h" - -#define CONFIG_SCHEMA "org.freedesktop.Tracker.Extract" -#define CONFIG_PATH "/org/freedesktop/tracker/extract/" - -static void config_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void config_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void config_finalize (GObject *object); -static void config_constructed (GObject *object); - -enum { - PROP_0, - PROP_VERBOSITY, - PROP_SCHED_IDLE, - PROP_MAX_BYTES, - PROP_MAX_MEDIA_ART_WIDTH, - PROP_WAIT_FOR_MINER_FS, -}; - -G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_SETTINGS); - -static void -tracker_config_class_init (TrackerConfigClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->set_property = config_set_property; - object_class->get_property = config_get_property; - object_class->finalize = config_finalize; - object_class->constructed = config_constructed; - - /* General */ - g_object_class_install_property (object_class, - PROP_VERBOSITY, - g_param_spec_enum ("verbosity", - "Log verbosity", - "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)", - TRACKER_TYPE_VERBOSITY, - TRACKER_VERBOSITY_ERRORS, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_SCHED_IDLE, - g_param_spec_enum ("sched-idle", - "Scheduler priority when idle", - "Scheduler priority when idle (0=always, 1=first-index, 2=never)", - TRACKER_TYPE_SCHED_IDLE, - TRACKER_SCHED_IDLE_FIRST_INDEX, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_MAX_BYTES, - g_param_spec_int ("max-bytes", - "Max Bytes", - "Maximum number of UTF-8 bytes to extract per file [0->10485760]", - 0, 1024 * 1024 * 10, - 1024 * 1024, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_WAIT_FOR_MINER_FS, - g_param_spec_boolean ("wait-for-miner-fs", - "Wait for FS miner to be done before extracting", - "%TRUE to wait for tracker-miner-fs is done before extracting. %FAlSE otherwise", - FALSE, - G_PARAM_READWRITE)); -} - -static void -tracker_config_init (TrackerConfig *object) -{ -} - -static void -config_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TrackerConfig *config = TRACKER_CONFIG (object); - - switch (param_id) { - /* General */ - /* NOTE: We handle these because we have to be able - * to save these based on command line overrides. - */ - case PROP_VERBOSITY: - tracker_config_set_verbosity (config, g_value_get_enum (value)); - break; - - /* We don't care about the others... we don't save anyway. */ - case PROP_SCHED_IDLE: - case PROP_MAX_BYTES: - case PROP_MAX_MEDIA_ART_WIDTH: - case PROP_WAIT_FOR_MINER_FS: - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void -config_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TrackerConfig *config = TRACKER_CONFIG (object); - - switch (param_id) { - case PROP_VERBOSITY: - g_value_set_enum (value, - tracker_config_get_verbosity (config)); - break; - - case PROP_SCHED_IDLE: - g_value_set_enum (value, - tracker_config_get_sched_idle (config)); - break; - - case PROP_MAX_BYTES: - g_value_set_int (value, - tracker_config_get_max_bytes (config)); - break; - - case PROP_WAIT_FOR_MINER_FS: - g_value_set_boolean (value, - tracker_config_get_wait_for_miner_fs (config)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void -config_finalize (GObject *object) -{ - /* For now we do nothing here, we left this override in for - * future expansion. - */ - - (G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object); -} - -static void -config_constructed (GObject *object) -{ - GSettings *settings; - - (G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object); - - settings = G_SETTINGS (object); - - if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) { - g_settings_delay (settings); - } - - /* Set up bindings: - * - * What's interesting here is that 'verbosity' and - * 'initial-sleep' are command line arguments that can be - * overridden, so we don't update the config when we set them - * from main() because it's a session configuration only, not - * a permanent one. To do this we use the flag - * G_SETTINGS_BIND_GET_NO_CHANGES. - * - * For the other settings, we don't bind the - * G_SETTINGS_BIND_SET because we don't want to save anything, - * ever, we only want to know about updates to the settings as - * they're changed externally. The only time this may be - * different is where we use the environment variable - * TRACKER_USE_CONFIG_FILES and we want to write a config - * file for convenience. But this is only necessary if the - * config is different to the default. - */ - g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_GET_NO_CHANGES); - g_settings_bind (settings, "sched-idle", object, "sched-idle", G_SETTINGS_BIND_GET); - g_settings_bind (settings, "wait-for-miner-fs", object, "wait-for-miner-fs", G_SETTINGS_BIND_GET); - - /* Cache settings accessed from extractor modules, we don't want - * the GSettings object accessed within these as it may trigger - * unintended open() calls. - */ - TRACKER_CONFIG (settings)->max_bytes = g_settings_get_int (settings, "max-bytes"); -} - -TrackerConfig * -tracker_config_new (void) -{ - TrackerConfig *config = NULL; - - /* FIXME: should we unset GSETTINGS_BACKEND env var? */ - - if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) { - GSettingsBackend *backend; - gchar *filename, *basename; - gboolean need_to_save; - - basename = g_strdup_printf ("%s.cfg", g_get_prgname ()); - filename = g_build_filename (g_get_user_config_dir (), "tracker", basename, NULL); - g_free (basename); - - need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE; - - backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General"); - g_info ("Using config file '%s'", filename); - g_free (filename); - - config = g_object_new (TRACKER_TYPE_CONFIG, - "backend", backend, - "schema-id", CONFIG_SCHEMA, - "path", CONFIG_PATH, - NULL); - g_object_unref (backend); - - if (need_to_save) { - g_info (" Config file does not exist, using default values..."); - } - } else { - config = g_object_new (TRACKER_TYPE_CONFIG, - "schema-id", CONFIG_SCHEMA, - "path", CONFIG_PATH, - NULL); - } - - return config; -} - -gint -tracker_config_get_verbosity (TrackerConfig *config) -{ - g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_VERBOSITY_ERRORS); - - return g_settings_get_enum (G_SETTINGS (config), "verbosity"); -} - -void -tracker_config_set_verbosity (TrackerConfig *config, - gint value) -{ - g_return_if_fail (TRACKER_IS_CONFIG (config)); - - g_settings_set_enum (G_SETTINGS (config), "verbosity", value); -} - -gint -tracker_config_get_sched_idle (TrackerConfig *config) -{ - g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_SCHED_IDLE_FIRST_INDEX); - - return g_settings_get_enum (G_SETTINGS (config), "sched-idle"); -} - -gint -tracker_config_get_max_bytes (TrackerConfig *config) -{ - g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0); - - return config->max_bytes; -} - -gboolean -tracker_config_get_wait_for_miner_fs (TrackerConfig *config) -{ - g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE); - - return g_settings_get_boolean (G_SETTINGS (config), "wait-for-miner-fs"); -} diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-config.h tracker-miners-2.3.3.new/src/tracker-extract/tracker-config.h --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-config.h 2020-03-10 05:54:32.662933300 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-config.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2009, Nokia <ivan.frade@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __TRACKER_EXTRACT_CONFIG_H__ -#define __TRACKER_EXTRACT_CONFIG_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define TRACKER_TYPE_CONFIG (tracker_config_get_type ()) -#define TRACKER_CONFIG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_CONFIG, TrackerConfig)) -#define TRACKER_CONFIG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_CONFIG, TrackerConfigClass)) -#define TRACKER_IS_CONFIG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_CONFIG)) -#define TRACKER_IS_CONFIG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_CONFIG)) -#define TRACKER_CONFIG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_CONFIG, TrackerConfigClass)) - -typedef struct TrackerConfig TrackerConfig; -typedef struct TrackerConfigClass TrackerConfigClass; - -struct TrackerConfig { - GSettings parent; - gint max_bytes; -}; - -struct TrackerConfigClass { - GSettingsClass parent_class; -}; - -GType tracker_config_get_type (void) G_GNUC_CONST; - -TrackerConfig *tracker_config_new (void); -gint tracker_config_get_verbosity (TrackerConfig *config); -gint tracker_config_get_sched_idle (TrackerConfig *config); -gint tracker_config_get_max_bytes (TrackerConfig *config); -gboolean tracker_config_get_wait_for_miner_fs (TrackerConfig *config); - -void tracker_config_set_verbosity (TrackerConfig *config, - gint value); - -G_END_DECLS - -#endif /* __TRACKER_EXTRACT_CONFIG_H__ */ - diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract.c 2020-03-10 05:54:32.668933600 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract.c 2023-12-08 15:11:34.511926407 +0800 @@ -30,8 +30,6 @@ #include <gio/gunixinputstream.h> #include <gio/gunixfdlist.h> -#include <libtracker-miners-common/tracker-common.h> - #include <libtracker-extract/tracker-extract.h> #include "tracker-extract.h" @@ -45,6 +43,8 @@ G_DEFINE_QUARK (TrackerExtractError, tracker_extract_error) +#define DEFAULT_MAX_TEXT 1048576 + extern gboolean debug; typedef struct { @@ -56,6 +56,8 @@ GHashTable *statistics_data; GList *running_tasks; + gint max_text; + /* used to maintain the running tasks * and stats from different threads */ @@ -83,6 +85,7 @@ GAsyncResult *res; gchar *file; gchar *mimetype; + gint max_text; TrackerMimetypeInfo *mimetype_handlers; @@ -127,6 +130,7 @@ priv->statistics_data = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) statistics_data_free); priv->single_thread_extractors = g_hash_table_new (NULL, NULL); + priv->max_text = DEFAULT_MAX_TEXT; priv->thread_pool = g_thread_pool_new ((GFunc) get_metadata, NULL, 10, TRUE, NULL); @@ -275,7 +279,7 @@ *info_out = NULL; file = g_file_new_for_uri (task->file); - info = tracker_extract_info_new (file, task->mimetype); + info = tracker_extract_info_new (file, task->mimetype, task->max_text); g_object_unref (file); if (task->mimetype && *task->mimetype) { @@ -343,6 +347,7 @@ GAsyncResult *res, GError **error) { + TrackerExtractPrivate *priv = TRACKER_EXTRACT_GET_PRIVATE (extract); TrackerExtractTask *task; gchar *mimetype_used; @@ -379,6 +384,7 @@ task->file = g_strdup (uri); task->mimetype = mimetype_used; task->extract = extract; + task->max_text = priv->max_text; if (task->cancellable) { task->signal_id = g_cancellable_connect (cancellable, @@ -497,9 +503,6 @@ static gpointer single_thread_get_metadata (GAsyncQueue *queue) { - if (!tracker_seccomp_init ()) - g_assert_not_reached (); - while (TRUE) { TrackerExtractTask *task; @@ -777,3 +780,12 @@ return g_task_propagate_pointer (G_TASK (res), error); } + +void +tracker_extract_set_max_text (TrackerExtract *extract, + gint max_text) +{ + TrackerExtractPrivate *priv = TRACKER_EXTRACT_GET_PRIVATE (extract); + + priv->max_text = max_text; +} diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-controller.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-controller.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-controller.c 2020-03-10 05:54:32.663933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-controller.c 2023-12-08 15:25:30.124273726 +0800 @@ -23,192 +23,102 @@ #include "tracker-main.h" +#include <gio/gunixfdlist.h> + enum { PROP_DECORATOR = 1, PROP_CONNECTION, + PROP_PERSISTENCE, }; struct TrackerExtractControllerPrivate { TrackerDecorator *decorator; - TrackerConfig *config; + TrackerExtractPersistence *persistence; GCancellable *cancellable; GDBusConnection *connection; - guint watch_id; - guint progress_signal_id; + GDBusProxy *miner_proxy; gint paused; }; G_DEFINE_TYPE_WITH_PRIVATE (TrackerExtractController, tracker_extract_controller, G_TYPE_OBJECT) static void -files_miner_idleness_changed (TrackerExtractController *self, - gboolean idle) -{ - if (idle && self->priv->paused) { - tracker_miner_resume (TRACKER_MINER (self->priv->decorator)); - self->priv->paused = FALSE; - } else if (!idle && !self->priv->paused) { - self->priv->paused = FALSE; - tracker_miner_pause (TRACKER_MINER (self->priv->decorator)); - } -} - -static void -files_miner_status_changed (TrackerExtractController *self, - const gchar *status) -{ - files_miner_idleness_changed (self, g_str_equal (status, "Idle")); -} - -static void -files_miner_get_status_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) +update_extract_config (TrackerExtractController *controller, + GDBusProxy *proxy) { - TrackerExtractController *self = user_data; - GDBusConnection *conn = (GDBusConnection *) source; - GVariant *reply; - const gchar *status; - GError *error = NULL; - - reply = g_dbus_connection_call_finish (conn, result, &error); - if (!reply) { - g_debug ("Failed to get tracker-miner-fs status: %s", - error->message); - g_clear_error (&error); - } else { - g_variant_get (reply, "(&s)", &status); - files_miner_status_changed (self, status); - g_variant_unref (reply); - } - - g_clear_object (&self->priv->cancellable); - g_object_unref (self); -} + TrackerExtractControllerPrivate *priv; + GVariantIter iter; + g_autoptr (GVariant) v = NULL; + GVariant *value; + gchar *key; -static void -appeared_cb (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, - gpointer user_data) -{ - TrackerExtractController *self = user_data; + priv = tracker_extract_controller_get_instance_private (controller); - /* Get initial status */ - self->priv->cancellable = g_cancellable_new (); - g_dbus_connection_call (connection, - "org.freedesktop.Tracker1.Miner.Files", - "/org/freedesktop/Tracker1/Miner/Files", - "org.freedesktop.Tracker1.Miner", - "GetStatus", - NULL, - G_VARIANT_TYPE ("(s)"), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - -1, - self->priv->cancellable, - files_miner_get_status_cb, - g_object_ref (self)); -} - -static void -vanished_cb (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - TrackerExtractController *self = user_data; - - /* tracker-miner-fs vanished, we don't have anything to wait for - * anymore. */ - files_miner_idleness_changed (self, TRUE); -} - -static void -files_miner_progress_cb (GDBusConnection *connection, - const gchar *sender_name, - const gchar *object_path, - const gchar *interface_name, - const gchar *signal_name, - GVariant *parameters, - gpointer user_data) -{ - TrackerExtractController *self = user_data; - const gchar *status; - - g_return_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sdi)"))); - - /* If we didn't get the initial status yet, ignore Progress signals */ - if (self->priv->cancellable) + v = g_dbus_proxy_get_cached_property (proxy, "ExtractorConfig"); + if (!v) return; - g_variant_get (parameters, "(&sdi)", &status, NULL, NULL); - files_miner_status_changed (self, status); -} + g_variant_iter_init (&iter, v); -static void -disconnect_all (TrackerExtractController *self) -{ - GDBusConnection *conn = self->priv->connection; + while (g_variant_iter_next (&iter, "{sv}", &key, &value)) { + if (g_strcmp0 (key, "max-bytes") == 0 && + g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)) { + TrackerExtract *extract = NULL; + gint max_bytes; + + max_bytes = g_variant_get_int32 (value); + g_object_get (priv->decorator, "extractor", &extract, NULL); + + if (extract) { + tracker_extract_set_max_text (extract, max_bytes); + g_object_unref (extract); + } + } - if (self->priv->watch_id != 0) - g_bus_unwatch_name (self->priv->watch_id); - self->priv->watch_id = 0; - - if (self->priv->progress_signal_id != 0) - g_dbus_connection_signal_unsubscribe (conn, - self->priv->progress_signal_id); - self->priv->progress_signal_id = 0; - - if (self->priv->cancellable) - g_cancellable_cancel (self->priv->cancellable); - g_clear_object (&self->priv->cancellable); + g_free (key); + g_variant_unref (value); + } } -static void -update_wait_for_miner_fs (TrackerExtractController *self) -{ - GDBusConnection *conn = self->priv->connection; - - if (tracker_config_get_wait_for_miner_fs (self->priv->config)) { - self->priv->progress_signal_id = - g_dbus_connection_signal_subscribe (conn, - "org.freedesktop.Tracker1.Miner.Files", - "org.freedesktop.Tracker1.Miner", - "Progress", - "/org/freedesktop/Tracker1/Miner/Files", - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - files_miner_progress_cb, - self, NULL); - - /* appeared_cb is guaranteed to be called even if the service - * was already running, so we'll start the miner from there. */ - self->priv->watch_id = g_bus_watch_name_on_connection (conn, - "org.freedesktop.Tracker1.Miner.Files", - G_BUS_NAME_WATCHER_FLAGS_NONE, - appeared_cb, - vanished_cb, - self, NULL); - } else { - disconnect_all (self); - files_miner_idleness_changed (self, TRUE); - } +static gboolean +set_up_persistence (TrackerExtractController *controller, + GCancellable *cancellable, + GError **error) +{ + TrackerExtractControllerPrivate *priv = + tracker_extract_controller_get_instance_private (controller); + g_autoptr (GUnixFDList) out_fd_list = NULL; + g_autoptr (GVariant) variant = NULL; + int idx, fd; + + variant = g_dbus_proxy_call_with_unix_fd_list_sync (priv->miner_proxy, + "GetPersistenceStorage", + NULL, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &out_fd_list, + cancellable, + error); + if (!variant) + return FALSE; + + g_variant_get (variant, "(h)", &idx); + fd = g_unix_fd_list_get (out_fd_list, idx, error); + if (fd < 0) + return FALSE; + + tracker_extract_persistence_set_fd (priv->persistence, fd); + return TRUE; } static void -tracker_extract_controller_constructed (GObject *object) +miner_properties_changed_cb (GDBusProxy *proxy, + GVariant *changed_properties, + GStrv invalidated_properties, + gpointer user_data) { - TrackerExtractController *self = (TrackerExtractController *) object; - - G_OBJECT_CLASS (tracker_extract_controller_parent_class)->constructed (object); - - g_assert (self->priv->decorator != NULL); - - self->priv->config = g_object_ref (tracker_main_get_config ()); - g_signal_connect_object (self->priv->config, - "notify::wait-for-miner-fs", - G_CALLBACK (update_wait_for_miner_fs), - self, G_CONNECT_SWAPPED); - update_wait_for_miner_fs (self); + update_extract_config (user_data, proxy); } static void @@ -226,6 +136,12 @@ case PROP_CONNECTION: g_value_set_object (value, self->priv->connection); break; + case PROP_PERSISTENCE: + g_value_set_object (value, self->priv->persistence); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; } } @@ -245,17 +161,47 @@ case PROP_CONNECTION: self->priv->connection = g_value_dup_object (value); break; + case PROP_PERSISTENCE: + self->priv->persistence = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; } } static void +tracker_extract_controller_constructed (GObject *object) +{ + TrackerExtractController *self = (TrackerExtractController *) object; + + G_OBJECT_CLASS (tracker_extract_controller_parent_class)->constructed (object); + + g_assert (self->priv->decorator != NULL); + + self->priv->miner_proxy = g_dbus_proxy_new_sync (self->priv->connection, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + "org.freedesktop.Tracker1.Miner.Files", + "/org/freedesktop/Tracker1/Files", + "org.freedesktop.Tracker1.Files", + NULL, NULL); + if (self->priv->miner_proxy) { + g_signal_connect (self->priv->miner_proxy, "g-properties-changed", + G_CALLBACK (miner_properties_changed_cb), object); + update_extract_config (self, self->priv->miner_proxy); + } + + set_up_persistence (self, NULL, NULL); +} + +static void tracker_extract_controller_dispose (GObject *object) { TrackerExtractController *self = (TrackerExtractController *) object; - disconnect_all (self); g_clear_object (&self->priv->decorator); - g_clear_object (&self->priv->config); + g_clear_object (&self->priv->persistence); G_OBJECT_CLASS (tracker_extract_controller_parent_class)->dispose (object); } @@ -288,6 +234,14 @@ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_PERSISTENCE, + g_param_spec_object ("persistence", + NULL, NULL, + TRACKER_TYPE_EXTRACT_PERSISTENCE, + G_PARAM_STATIC_STRINGS | + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); } static void @@ -297,13 +251,15 @@ } TrackerExtractController * -tracker_extract_controller_new (TrackerDecorator *decorator, - GDBusConnection *connection) +tracker_extract_controller_new (TrackerDecorator *decorator, + GDBusConnection *connection, + TrackerExtractPersistence *persistence) { g_return_val_if_fail (TRACKER_IS_DECORATOR (decorator), NULL); return g_object_new (TRACKER_TYPE_EXTRACT_CONTROLLER, "decorator", decorator, "connection", connection, + "persistence", persistence, NULL); } diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-controller.h tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-controller.h --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-controller.h 2020-03-10 05:54:32.663933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-controller.h 2023-12-08 15:11:34.511926407 +0800 @@ -47,8 +47,9 @@ }; GType tracker_extract_controller_get_type (void) G_GNUC_CONST; -TrackerExtractController * tracker_extract_controller_new (TrackerDecorator *decorator, - GDBusConnection *connection); +TrackerExtractController * tracker_extract_controller_new (TrackerDecorator *decorator, + GDBusConnection *connection, + TrackerExtractPersistence *persistence); G_END_DECLS diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-decorator.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-decorator.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-decorator.c 2020-03-10 05:54:32.663933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-decorator.c 2023-12-08 16:34:43.175695023 +0800 @@ -27,7 +27,9 @@ #include "tracker-extract-priority-dbus.h" enum { - PROP_EXTRACTOR = 1 + PROP_0, + PROP_EXTRACTOR, + PROP_PERSISTENCE, }; #define TRACKER_EXTRACT_DATA_SOURCE TRACKER_PREFIX_TRACKER "extractor-data-source" @@ -83,6 +85,11 @@ static void decorator_get_next_file (TrackerDecorator *decorator); static void tracker_extract_decorator_initable_iface_init (GInitableIface *iface); +static void decorator_ignore_file (GFile *file, + TrackerExtractDecorator *decorator, + const gchar *error_message, + const gchar *extra_info); + G_DEFINE_TYPE_WITH_CODE (TrackerExtractDecorator, tracker_extract_decorator, TRACKER_TYPE_DECORATOR_FS, G_ADD_PRIVATE (TrackerExtractDecorator) @@ -102,6 +109,12 @@ case PROP_EXTRACTOR: g_value_set_object (value, priv->extractor); break; + case PROP_PERSISTENCE: + g_value_set_object (value, priv->persistence); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; } } @@ -119,6 +132,12 @@ case PROP_EXTRACTOR: priv->extractor = g_value_dup_object (value); break; + case PROP_PERSISTENCE: + priv->persistence = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; } } @@ -135,6 +154,8 @@ if (priv->timer) g_timer_destroy (priv->timer); + g_clear_object (&priv->persistence); + g_object_unref (priv->iface); g_hash_table_unref (priv->apps); g_hash_table_unref (priv->recovery_files); @@ -185,7 +206,7 @@ priv = tracker_extract_decorator_get_instance_private (TRACKER_EXTRACT_DECORATOR (data->decorator)); info = tracker_extract_file_finish (extract, result, &error); - tracker_extract_persistence_remove_file (priv->persistence, data->file); + tracker_extract_persistence_set_file (priv->persistence, NULL); g_hash_table_remove (priv->recovery_files, tracker_decorator_info_get_url (data->decorator_info)); if (error) { @@ -284,7 +305,7 @@ g_message ("Extracting metadata for '%s'", tracker_decorator_info_get_url (info)); - tracker_extract_persistence_add_file (priv->persistence, data->file); + tracker_extract_persistence_set_file (priv->persistence, data->file); tracker_extract_file (priv->extractor, tracker_decorator_info_get_url (info), @@ -344,6 +365,22 @@ } static void +tracker_extract_decorator_started (TrackerMiner *miner) +{ + TrackerExtractDecorator *decorator = TRACKER_EXTRACT_DECORATOR (miner); + TrackerExtractDecoratorPrivate *priv = + tracker_extract_decorator_get_instance_private (decorator); + GFile *file; + + file = tracker_extract_persistence_get_file (priv->persistence); + + if (file) + decorator_ignore_file (file, decorator, "Crash/hang handling file", NULL); + + TRACKER_MINER_CLASS (tracker_extract_decorator_parent_class)->started (miner); +} + +static void tracker_extract_decorator_items_available (TrackerDecorator *decorator) { TrackerExtractDecoratorPrivate *priv; @@ -546,6 +583,7 @@ miner_class->paused = tracker_extract_decorator_paused; miner_class->resumed = tracker_extract_decorator_resumed; + miner_class->started = tracker_extract_decorator_started; decorator_class->items_available = tracker_extract_decorator_items_available; decorator_class->finished = tracker_extract_decorator_finished; @@ -557,33 +595,30 @@ "Extractor", TRACKER_TYPE_EXTRACT, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); -} - -static void -decorator_retry_file (GFile *file, - gpointer user_data) -{ - TrackerExtractDecorator *decorator = user_data; - TrackerExtractDecoratorPrivate *priv = tracker_extract_decorator_get_instance_private (decorator); - gchar *path; - - path = g_file_get_uri (file); - g_hash_table_insert (priv->recovery_files, path, g_object_ref (file)); - tracker_decorator_fs_prepend_file (TRACKER_DECORATOR_FS (decorator), file); + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, + PROP_PERSISTENCE, + g_param_spec_object ("persistence", + NULL, NULL, + TRACKER_TYPE_EXTRACT_PERSISTENCE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } static void -decorator_ignore_file (GFile *file, - gpointer user_data) +decorator_ignore_file (GFile *file, + TrackerExtractDecorator *decorator, + const gchar *error_message, + const gchar *extra_info) { - TrackerExtractDecorator *decorator = user_data; TrackerSparqlConnection *conn; GError *error = NULL; gchar *uri, *query; uri = g_file_get_uri (file); - g_message ("Extraction on file '%s' has been attempted too many times, ignoring", uri); + g_message ("Extraction on file '%s' failed in previous execution, ignoring", uri); conn = tracker_miner_get_connection (TRACKER_MINER (decorator)); query = g_strdup_printf ("INSERT { GRAPH <" TRACKER_OWN_GRAPH_URN "> {" @@ -666,9 +701,6 @@ ret = FALSE; } - priv->persistence = tracker_extract_persistence_initialize (decorator_retry_file, - decorator_ignore_file, - decorator); out: g_clear_object (&conn); @@ -683,14 +715,18 @@ } TrackerDecorator * -tracker_extract_decorator_new (TrackerExtract *extract, - GCancellable *cancellable, - GError **error) +tracker_extract_decorator_new (TrackerSparqlConnection *connection, + TrackerExtract *extract, + TrackerExtractPersistence *persistence, + GCancellable *cancellable, + GError **error) { return g_initable_new (TRACKER_TYPE_EXTRACT_DECORATOR, cancellable, error, + "connection", connection, "data-source", TRACKER_EXTRACT_DATA_SOURCE, "class-names", supported_classes, "extractor", extract, + "persistence", persistence, NULL); } diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-decorator.h tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-decorator.h --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-decorator.h 2020-03-10 05:54:32.663933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-decorator.h 2023-12-08 16:34:58.825779661 +0800 @@ -24,6 +24,7 @@ #include <libtracker-miner/tracker-miner.h> #include "tracker-extract.h" +#include "tracker-extract-persistence.h" G_BEGIN_DECLS @@ -47,10 +48,11 @@ GType tracker_extract_decorator_get_type (void) G_GNUC_CONST; -TrackerDecorator * tracker_extract_decorator_new (TrackerExtract *extractor, - GCancellable *cancellable, - GError **error); - +TrackerDecorator * tracker_extract_decorator_new (TrackerSparqlConnection *connection, + TrackerExtract *extract, + TrackerExtractPersistence *persistence, + GCancellable *cancellable, + GError **error); G_END_DECLS #endif /* __TRACKER_EXTRACT_DECORATOR_H__ */ diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-epub.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-epub.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-epub.c 2020-03-10 05:54:32.664933400 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-epub.c 2023-12-08 15:11:34.511926407 +0800 @@ -561,12 +561,12 @@ } static gchar * -extract_opf_contents (const gchar *uri, - const gchar *content_prefix, - GList *content_files) +extract_opf_contents (TrackerExtractInfo *info, + const gchar *uri, + const gchar *content_prefix, + GList *content_files) { OPFContentData content_data = { 0 }; - TrackerConfig *config; GError *error = NULL; GList *l; GMarkupParser xml_parser = { @@ -575,10 +575,8 @@ NULL, NULL }; - config = tracker_main_get_config (); - content_data.contents = g_string_new (""); - content_data.limit = (gsize) tracker_config_get_max_bytes (config); + content_data.limit = (gsize) tracker_extract_info_get_max_text (info); g_debug ("Extracting up to %" G_GSIZE_FORMAT " bytes of content", content_data.limit); @@ -611,8 +609,9 @@ } static TrackerResource * -extract_opf (const gchar *uri, - const gchar *opf_path) +extract_opf (TrackerExtractInfo *info, + const gchar *uri, + const gchar *opf_path) { TrackerResource *ebook; GMarkupParseContext *context; @@ -652,7 +651,7 @@ } dirname = g_path_get_dirname (opf_path); - contents = extract_opf_contents (uri, dirname, data->pages); + contents = extract_opf_contents (info, uri, dirname, data->pages); g_free (dirname); if (contents && *contents) { @@ -682,7 +681,7 @@ return FALSE; } - ebook = extract_opf (uri, opf_path); + ebook = extract_opf (info, uri, opf_path); g_free (opf_path); g_free (uri); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-gstreamer.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-gstreamer.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-gstreamer.c 2020-03-10 05:54:32.664933400 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-gstreamer.c 2023-12-08 15:11:34.511926407 +0800 @@ -1312,12 +1312,16 @@ /* Lifted from totem-video-thumbnailer */ const gchar *blacklisted[] = { "bcmdec", + "camerabin", + "fluidsynthmidi", + "libcamera" "vaapi", "video4linux2" }; GstRegistry *registry; guint i; + gst_registry_fork_set_enabled (FALSE); gst_init (NULL, NULL); registry = gst_registry_get (); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract.h tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract.h --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract.h 2020-03-10 05:54:32.669933600 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract.h 2023-12-08 15:11:34.511926407 +0800 @@ -73,6 +73,9 @@ void tracker_extract_dbus_start (TrackerExtract *extract); void tracker_extract_dbus_stop (TrackerExtract *extract); +void tracker_extract_set_max_text (TrackerExtract *extract, + gint max_text); + /* Not DBus API */ void tracker_extract_get_metadata_by_cmdline (TrackerExtract *object, const gchar *path, diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-html.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-html.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-html.c 2020-03-10 05:54:32.665933400 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-html.c 2023-12-08 15:11:34.511926407 +0800 @@ -233,7 +233,6 @@ { TrackerResource *metadata; GFile *file; - TrackerConfig *config; htmlDocPtr doc; parser_data pd; gchar *filename; @@ -283,8 +282,7 @@ pd.plain_text = g_string_new (NULL); pd.title = g_string_new (NULL); - config = tracker_main_get_config (); - pd.n_bytes_remaining = tracker_config_get_max_bytes (config); + pd.n_bytes_remaining = tracker_extract_info_get_max_text (info); filename = g_file_get_path (file); doc = htmlSAXParseFile (filename, NULL, &handler, &pd); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-msoffice.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-msoffice.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-msoffice.c 2020-03-10 05:54:32.666933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-msoffice.c 2023-12-08 15:11:34.515259759 +0800 @@ -1623,7 +1623,6 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) { TrackerResource *metadata; - TrackerConfig *config; GsfInfile *infile = NULL; gchar *content = NULL, *uri; gboolean is_encrypted = FALSE; @@ -1670,8 +1669,7 @@ extract_summary (metadata, infile, uri); /* Set max bytes to read from content */ - config = tracker_main_get_config (); - max_bytes = tracker_config_get_max_bytes (config); + max_bytes = tracker_extract_info_get_max_text (info); if (g_ascii_strcasecmp (mime_used, "application/msword") == 0) { /* Word file */ diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-msoffice-xml.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-msoffice-xml.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-msoffice-xml.c 2020-03-10 05:54:32.666933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-msoffice-xml.c 2023-12-08 15:11:34.515259759 +0800 @@ -814,7 +814,6 @@ MsOfficeXMLParserInfo info = { 0 }; MsOfficeXMLFileType file_type; TrackerResource *metadata; - TrackerConfig *config; GMarkupParseContext *context = NULL; GError *error = NULL; GFile *file; @@ -830,9 +829,6 @@ /* Get current Content Type */ file_type = msoffice_xml_get_file_type (uri); - /* Setup conf */ - config = tracker_main_get_config (); - g_debug ("Extracting MsOffice XML format..."); metadata = tracker_resource_new (NULL); @@ -848,7 +844,7 @@ info.content = NULL; info.title_already_set = FALSE; info.generator_already_set = FALSE; - info.bytes_pending = tracker_config_get_max_bytes (config); + info.bytes_pending = tracker_extract_info_get_max_text (extract_info); /* Create content-type parser context */ context = g_markup_parse_context_new (&content_types_parser, diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-oasis.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-oasis.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-oasis.c 2020-03-10 05:54:32.666933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-oasis.c 2023-12-08 15:11:34.515259759 +0800 @@ -170,7 +170,6 @@ tracker_extract_get_metadata (TrackerExtractInfo *extract_info) { TrackerResource *metadata; - TrackerConfig *config; ODTMetadataParseInfo info = { 0 }; ODTFileType file_type; GFile *file; @@ -195,9 +194,6 @@ file = tracker_extract_info_get_file (extract_info); uri = g_file_get_uri (file); - /* Setup conf */ - config = tracker_main_get_config (); - g_debug ("Extracting OASIS metadata and contents from '%s'", uri); /* First, parse metadata */ @@ -232,7 +228,7 @@ /* Extract content with the given limitations */ extract_oasis_content (uri, - tracker_config_get_max_bytes (config), + tracker_extract_info_get_max_text (extract_info), file_type, metadata); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-pdf.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-pdf.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-pdf.c 2020-03-10 05:54:32.667933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-pdf.c 2023-12-08 15:11:34.515259759 +0800 @@ -280,7 +280,6 @@ G_MODULE_EXPORT gboolean tracker_extract_get_metadata (TrackerExtractInfo *info) { - TrackerConfig *config; GTime creation_date; GError *error = NULL; TrackerResource *metadata; @@ -522,8 +521,7 @@ tracker_resource_set_int64 (metadata, "nfo:pageCount", poppler_document_get_n_pages(document)); - config = tracker_main_get_config (); - n_bytes = tracker_config_get_max_bytes (config); + n_bytes = tracker_extract_info_get_max_text (info); content = extract_content_text (document, n_bytes); if (content) { diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-persistence.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-persistence.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-persistence.c 2020-03-10 05:54:32.667933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-persistence.c 2023-12-08 15:11:34.515259759 +0800 @@ -19,255 +19,112 @@ #include "tracker-extract-persistence.h" -#define MAX_RETRIES 3 - typedef struct _TrackerExtractPersistencePrivate TrackerExtractPersistencePrivate; struct _TrackerExtractPersistencePrivate { - GFile *tmp_dir; + int fd; }; G_DEFINE_TYPE_WITH_PRIVATE (TrackerExtractPersistence, tracker_extract_persistence, G_TYPE_OBJECT) -static GQuark n_retries_quark = 0; - -static void -tracker_extract_persistence_class_init (TrackerExtractPersistenceClass *klass) -{ - n_retries_quark = g_quark_from_static_string ("tracker-extract-n-retries-quark"); -} - static void -tracker_extract_persistence_init (TrackerExtractPersistence *persistence) +tracker_extract_persistence_finalize (GObject *object) { - TrackerExtractPersistencePrivate *priv; - gchar *dirname, *tmp_path; - - priv = tracker_extract_persistence_get_instance_private (persistence); + TrackerExtractPersistence *persistence = + TRACKER_EXTRACT_PERSISTENCE (object); + TrackerExtractPersistencePrivate *priv = + tracker_extract_persistence_get_instance_private (persistence); - dirname = g_strdup_printf ("tracker-extract-files.%d", getuid ()); - tmp_path = g_build_filename (g_get_tmp_dir (), dirname, NULL); - g_free (dirname); - - if (g_mkdir_with_parents (tmp_path, 0700) != 0) { - g_critical ("The directory %s could not be created, or has the wrong permissions", - tmp_path); - g_assert_not_reached (); - } + if (priv->fd > 0) + close (priv->fd); - priv->tmp_dir = g_file_new_for_path (tmp_path); - g_free (tmp_path); + G_OBJECT_CLASS (tracker_extract_persistence_parent_class)->finalize (object); } static void -increment_n_retries (GFile *file) +tracker_extract_persistence_class_init (TrackerExtractPersistenceClass *klass) { - guint n_retries; + GObjectClass *object_class = G_OBJECT_CLASS (klass); - n_retries = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (file), n_retries_quark)); - g_object_set_qdata (G_OBJECT (file), n_retries_quark, GUINT_TO_POINTER (n_retries + 1)); + object_class->finalize = tracker_extract_persistence_finalize; } -static GFile * -persistence_create_symlink_file (TrackerExtractPersistence *persistence, - GFile *file) +static void +tracker_extract_persistence_init (TrackerExtractPersistence *persistence) { - TrackerExtractPersistencePrivate *priv; - guint n_retries = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (file), n_retries_quark)); - gchar *link_name, *path, *md5; - GFile *link_file; - - priv = tracker_extract_persistence_get_instance_private (persistence); - path = g_file_get_path (file); - md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, path, -1); - link_name = g_strdup_printf ("%d-%s", n_retries, md5); - link_file = g_file_get_child (priv->tmp_dir, link_name); - - g_free (link_name); - g_free (path); - g_free (md5); - - return link_file; } -static GFile * -persistence_symlink_get_file (GFileInfo *info) +TrackerExtractPersistence * +tracker_extract_persistence_new (void) { - const gchar *symlink_name, *symlink_target; - gchar *md5, **items; - GFile *file = NULL; - guint n_retries; - - symlink_name = g_file_info_get_name (info); - symlink_target = g_file_info_get_symlink_target (info); - - if (!g_path_is_absolute (symlink_target)) { - g_critical ("Symlink paths must be absolute, '%s' points to '%s'", - symlink_name, symlink_target); - return NULL; - } - - md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, symlink_target, -1); - items = g_strsplit (symlink_name, "-", 2); - n_retries = g_strtod (items[0], NULL); - - if (g_strcmp0 (items[1], md5) == 0) { - file = g_file_new_for_path (symlink_target); - g_object_set_qdata (G_OBJECT (file), n_retries_quark, - GUINT_TO_POINTER (n_retries)); - } else { - g_critical ("path MD5 for '%s' doesn't match with symlink '%s'", - symlink_target, symlink_name); - } - - g_strfreev (items); - g_free (md5); - - return file; + return g_object_new (TRACKER_TYPE_EXTRACT_PERSISTENCE, + NULL); } -static gboolean -persistence_store_file (TrackerExtractPersistence *persistence, - GFile *file) +void +tracker_extract_persistence_set_fd (TrackerExtractPersistence *persistence, + int fd) { - GError *error = NULL; - gboolean success; - GFile *link_file; - gchar *path; + TrackerExtractPersistencePrivate *priv = + tracker_extract_persistence_get_instance_private (persistence); - increment_n_retries (file); - path = g_file_get_path (file); - link_file = persistence_create_symlink_file (persistence, file); - - success = g_file_make_symbolic_link (link_file, path, NULL, &error); - - if (!success) { - g_warning ("Could not save '%s' into failsafe persistence store: %s", - path, error ? error->message : "no error given"); - g_clear_error (&error); - } - - g_object_unref (link_file); - g_free (path); - - return success; + if (priv->fd > 0) + close (priv->fd); + priv->fd = fd; } -static gboolean -persistence_remove_file (TrackerExtractPersistence *persistence, - GFile *file) +void +tracker_extract_persistence_set_file (TrackerExtractPersistence *persistence, + GFile *file) { - GError *error = NULL; - GFile *link_file; - gboolean success; + TrackerExtractPersistencePrivate *priv = + tracker_extract_persistence_get_instance_private (persistence); + g_autofree gchar *path = NULL; + int len, written = 0, retval; - link_file = persistence_create_symlink_file (persistence, file); - success = g_file_delete (link_file, NULL, &error); - - if (!success) { - gchar *path = g_file_get_path (file); + g_return_if_fail (TRACKER_IS_EXTRACT_PERSISTENCE (persistence)); + g_return_if_fail (!file || G_IS_FILE (file)); - g_warning ("Could not delete '%s' from failsafe persistence store", - path); - g_free (path); + if (file) { + path = g_file_get_path (file); + } else { + path = g_strdup (""); } - g_object_unref (link_file); + /* Write also the trailing \0 */ + len = strlen (path) + 1; - return success; -} + lseek (priv->fd, 0, SEEK_SET); -static void -persistence_retrieve_files (TrackerExtractPersistence *persistence, - TrackerFileRecoveryFunc retry_func, - TrackerFileRecoveryFunc ignore_func, - gpointer user_data) -{ - TrackerExtractPersistencePrivate *priv; - GFileEnumerator *enumerator; - GFileInfo *info; - - priv = tracker_extract_persistence_get_instance_private (persistence); - enumerator = g_file_enumerate_children (priv->tmp_dir, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, NULL); - if (!enumerator) - return; - - while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) { - GFile *file, *symlink_file; - guint n_retries; - - symlink_file = g_file_enumerator_get_child (enumerator, info); - file = persistence_symlink_get_file (info); - - if (!file) { - /* If we got here, persistence_symlink_get_file() already emitted a g_critical */ - g_object_unref (symlink_file); - g_object_unref (info); - continue; - } - - /* Delete the symlink, it will get probably added back soon after, - * and n_retries incremented. - */ - g_file_delete (symlink_file, NULL, NULL); - g_object_unref (symlink_file); - - n_retries = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (file), n_retries_quark)); - - /* Trigger retry/ignore func for the symlink target */ - if (n_retries >= MAX_RETRIES) { - ignore_func (file, user_data); - } else { - retry_func (file, user_data); - } + while (TRUE) { + retval = write (priv->fd, &path[written], len - written); + if (retval < 0) + break; - g_object_unref (file); - g_object_unref (info); + written += retval; + if (written >= len) + break; } - - g_file_enumerator_close (enumerator, NULL, NULL); - g_object_unref (enumerator); } -TrackerExtractPersistence * -tracker_extract_persistence_initialize (TrackerFileRecoveryFunc retry_func, - TrackerFileRecoveryFunc ignore_func, - gpointer user_data) -{ - static TrackerExtractPersistence *persistence = NULL; - - if (!persistence) { - persistence = g_object_new (TRACKER_TYPE_EXTRACT_PERSISTENCE, - NULL); - persistence_retrieve_files (persistence, - retry_func, ignore_func, - user_data); - } - - return persistence; -} - -void -tracker_extract_persistence_add_file (TrackerExtractPersistence *persistence, - GFile *file) +GFile * +tracker_extract_persistence_get_file (TrackerExtractPersistence *persistence) { - g_return_if_fail (TRACKER_IS_EXTRACT_PERSISTENCE (persistence)); - g_return_if_fail (G_IS_FILE (file)); + TrackerExtractPersistencePrivate *priv = + tracker_extract_persistence_get_instance_private (persistence); + gchar buf[2048]; + int len; - persistence_store_file (persistence, file); -} + g_return_val_if_fail (TRACKER_IS_EXTRACT_PERSISTENCE (persistence), NULL); -void -tracker_extract_persistence_remove_file (TrackerExtractPersistence *persistence, - GFile *file) -{ - g_return_if_fail (TRACKER_IS_EXTRACT_PERSISTENCE (persistence)); - g_return_if_fail (G_IS_FILE (file)); + lseek (priv->fd, 0, SEEK_SET); + len = read (priv->fd, buf, sizeof (buf)); + if (len <= 0) + return NULL; + if (buf[0] == '\0') + return NULL; - persistence_remove_file (persistence, file); + buf[len - 1] = '\0'; + return g_file_new_for_path (buf); } diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-persistence.h tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-persistence.h --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-persistence.h 2020-03-10 05:54:32.667933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-persistence.h 2023-12-08 15:11:34.515259759 +0800 @@ -34,9 +34,6 @@ typedef struct _TrackerExtractPersistence TrackerExtractPersistence; typedef struct _TrackerExtractPersistenceClass TrackerExtractPersistenceClass; -typedef void (* TrackerFileRecoveryFunc) (GFile *file, - gpointer user_data); - struct _TrackerExtractPersistence { GObject parent_instance; @@ -49,15 +46,15 @@ GType tracker_extract_persistence_get_type (void) G_GNUC_CONST; -TrackerExtractPersistence * - tracker_extract_persistence_initialize (TrackerFileRecoveryFunc retry_func, - TrackerFileRecoveryFunc ignore_func, - gpointer user_data); - -void tracker_extract_persistence_add_file (TrackerExtractPersistence *persistence, - GFile *file); -void tracker_extract_persistence_remove_file (TrackerExtractPersistence *persistence, - GFile *file); +TrackerExtractPersistence * tracker_extract_persistence_new (void); + +void tracker_extract_persistence_set_fd (TrackerExtractPersistence *persistence, + int fd); + +GFile * tracker_extract_persistence_get_file (TrackerExtractPersistence *persistence); + +void tracker_extract_persistence_set_file (TrackerExtractPersistence *persistence, + GFile *file); G_END_DECLS diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-text.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-text.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-extract-text.c 2020-03-10 05:54:32.667933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-extract-text.c 2023-12-08 15:11:34.515259759 +0800 @@ -79,12 +79,9 @@ tracker_extract_get_metadata (TrackerExtractInfo *info) { TrackerResource *metadata; - TrackerConfig *config; gchar *content = NULL; - config = tracker_main_get_config (); - - content = get_file_content (tracker_extract_info_get_file (info), tracker_config_get_max_bytes (config)); + content = get_file_content (tracker_extract_info_get_file (info), tracker_extract_info_get_max_text (info)); if (content == NULL) { /* An error occurred, perhaps the file was deleted. */ diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-main.c tracker-miners-2.3.3.new/src/tracker-extract/tracker-main.c --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-main.c 2020-03-10 05:54:32.669933600 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-main.c 2023-12-08 21:59:54.931523749 +0800 @@ -40,11 +40,11 @@ #include <libtracker-miners-common/tracker-common.h> -#include "tracker-config.h" #include "tracker-main.h" #include "tracker-extract.h" #include "tracker-extract-controller.h" #include "tracker-extract-decorator.h" +#include "tracker-extract-persistence.h" #ifdef THREAD_ENABLE_TRACE #warning Main thread traces enabled @@ -61,6 +61,7 @@ " http://www.gnu.org/licenses/gpl.txt\n" #define DBUS_NAME_SUFFIX "Tracker1.Miner.Extract" +#define MINER_FS_NAME_SUFFIX "Tracker1.Miner.Files" #define DBUS_PATH "/org/freedesktop/Tracker1/Miner/Extract" static GMainLoop *main_loop; @@ -74,8 +75,6 @@ static gchar *domain_ontology_name = NULL; static guint shutdown_timeout_id = 0; -static TrackerConfig *config; - static GOptionEntry entries[] = { { "verbosity", 'v', 0, G_OPTION_ARG_INT, &verbosity, @@ -134,86 +133,8 @@ } } -static void -initialize_directories (void) -{ - gchar *user_data_dir; - - /* NOTE: We don't create the database directories here, the - * tracker-db-manager does that for us. - */ - - user_data_dir = g_build_filename (g_get_user_data_dir (), - "tracker", - NULL); - - /* g_message ("Checking directory exists:'%s'", user_data_dir); */ - g_mkdir_with_parents (user_data_dir, 00755); - - g_free (user_data_dir); -} - -static gboolean -signal_handler (gpointer user_data) -{ - int signo = GPOINTER_TO_INT (user_data); - - static gboolean in_loop = FALSE; - - /* Die if we get re-entrant signals handler calls */ - if (in_loop) { - _exit (EXIT_FAILURE); - } - - switch (signo) { - case SIGTERM: - case SIGINT: - in_loop = TRUE; - g_main_loop_quit (main_loop); - - /* Fall through */ - default: - if (g_strsignal (signo)) { - g_print ("\n"); - g_print ("Received signal:%d->'%s'\n", - signo, - g_strsignal (signo)); - } - break; - } - - return G_SOURCE_CONTINUE; -} - -static void -initialize_signal_handler (void) -{ -#ifndef G_OS_WIN32 - g_unix_signal_add (SIGTERM, signal_handler, GINT_TO_POINTER (SIGTERM)); - g_unix_signal_add (SIGINT, signal_handler, GINT_TO_POINTER (SIGINT)); -#endif /* G_OS_WIN32 */ -} - -static void -sanity_check_option_values (TrackerConfig *config) -{ - g_message ("General options:"); - g_message (" Verbosity ............................ %d", - tracker_config_get_verbosity (config)); - g_message (" Sched Idle ........................... %d", - tracker_config_get_sched_idle (config)); - g_message (" Max bytes (per file) ................. %d", - tracker_config_get_max_bytes (config)); -} - -TrackerConfig * -tracker_main_get_config (void) -{ - return config; -} - static int -run_standalone (TrackerConfig *config) +run_standalone (void) { TrackerExtract *object; GFile *file; @@ -226,9 +147,6 @@ output_format_name = "turtle"; } - /* This makes sure we don't steal all the system's resources */ - initialize_priority_and_scheduling (); - /* Look up the output format by name */ enum_class = g_type_class_ref (TRACKER_TYPE_SERIALIZATION_FORMAT); enum_value = g_enum_get_value_by_nick (enum_class, output_format_name); @@ -300,19 +218,21 @@ main_loop); } -int -main (int argc, char *argv[]) +static int +do_main (int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; TrackerExtract *extract; TrackerDecorator *decorator; TrackerExtractController *controller; - gchar *log_filename = NULL; GMainLoop *my_main_loop; GDBusConnection *connection; TrackerMinerProxy *proxy; - gchar *dbus_domain_name, *dbus_name; + TrackerSparqlConnection *sparql_connection; + TrackerExtractPersistence *persistence; + TrackerDomainOntology *domain_ontology; + gchar *domain_name, *dbus_name; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); @@ -358,7 +278,7 @@ tracker_sparql_connection_set_domain (domain_ontology_name); - tracker_load_domain_config (domain_ontology_name, &dbus_domain_name, &error); + domain_ontology = tracker_domain_ontology_new (domain_ontology_name, NULL, &error); if (error) { g_critical ("Could not load domain ontology '%s': %s", @@ -367,9 +287,6 @@ return EXIT_FAILURE; } - /* This makes sure we don't steal all the system's resources */ - initialize_priority_and_scheduling (); - connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &error); if (error) { g_critical ("Could not create DBus connection: %s\n", @@ -378,45 +295,36 @@ return EXIT_FAILURE; } - config = tracker_config_new (); - - /* Extractor command line arguments */ - if (verbosity > -1) { - tracker_config_set_verbosity (config, verbosity); - } - - tracker_log_init (tracker_config_get_verbosity (config), &log_filename); - if (log_filename != NULL) { - g_message ("Using log file:'%s'", log_filename); - g_free (log_filename); - } - - sanity_check_option_values (config); - /* Set conditions when we use stand alone settings */ if (filename) { - return run_standalone (config); + return run_standalone (); } - /* Initialize subsystems */ - initialize_directories (); - extract = tracker_extract_new (TRUE, force_module); if (!extract) { - g_object_unref (config); - tracker_log_shutdown (); return EXIT_FAILURE; } tracker_module_manager_load_modules (); - decorator = tracker_extract_decorator_new (extract, NULL, &error); + dbus_name = tracker_domain_ontology_get_domain (domain_ontology, MINER_FS_NAME_SUFFIX); + sparql_connection = tracker_sparql_connection_bus_new (dbus_name, + NULL, &error); + + if (error) { + g_critical ("Could not connect to filesystem miner endpoint: %s", + error->message); + g_error_free (error); + return EXIT_FAILURE; + } + + persistence = tracker_extract_persistence_new (); + + decorator = tracker_extract_decorator_new (sparql_connection, extract, persistence, NULL, &error); if (error) { g_critical ("Could not start decorator: %s\n", error->message); - g_object_unref (config); - tracker_log_shutdown (); return EXIT_FAILURE; } @@ -425,8 +333,6 @@ g_critical ("Could not create miner DBus proxy: %s\n", error->message); g_error_free (error); g_object_unref (decorator); - g_object_unref (config); - tracker_log_shutdown (); return EXIT_FAILURE; } @@ -437,11 +343,10 @@ tracker_locale_sanity_check (); - controller = tracker_extract_controller_new (decorator, connection); - tracker_miner_start (TRACKER_MINER (decorator)); + controller = tracker_extract_controller_new (decorator, connection, persistence); /* Request DBus name */ - dbus_name = g_strconcat (dbus_domain_name, ".", DBUS_NAME_SUFFIX, NULL); + dbus_name = tracker_domain_ontology_get_domain (domain_ontology, DBUS_NAME_SUFFIX); if (!tracker_dbus_request_name (connection, dbus_name, &error)) { g_critical ("Could not request DBus name '%s': %s", @@ -456,16 +361,18 @@ /* Main loop */ main_loop = g_main_loop_new (NULL, FALSE); - if (domain_ontology_name) { + if (domain_ontology && domain_ontology_name) { /* If we are running for a specific domain, we tie the lifetime of this * process to the domain. For example, if the domain name is * org.example.MyApp then this tracker-extract process will exit as * soon as org.example.MyApp exits. */ - g_bus_watch_name_on_connection (connection, dbus_domain_name, + domain_name = tracker_domain_ontology_get_domain (domain_ontology, NULL); + g_bus_watch_name_on_connection (connection, domain_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, on_domain_vanished, main_loop, NULL); + g_free (domain_name); } g_signal_connect (decorator, "finished", @@ -475,7 +382,7 @@ G_CALLBACK (on_decorator_items_available), main_loop); - initialize_signal_handler (); + tracker_miner_start (TRACKER_MINER (decorator)); g_main_loop_run (main_loop); @@ -489,13 +396,25 @@ g_object_unref (extract); g_object_unref (decorator); g_object_unref (controller); + g_object_unref (persistence); g_object_unref (proxy); g_object_unref (connection); - g_free (dbus_domain_name); + tracker_domain_ontology_unref (domain_ontology); + g_object_unref (sparql_connection); - tracker_log_shutdown (); + return EXIT_SUCCESS; +} - g_object_unref (config); +int +main (int argc, char *argv[]) +{ + /* This function is untouchable! Add things to do_main() */ - return EXIT_SUCCESS; + /* This makes sure we don't steal all the system's resources */ + initialize_priority_and_scheduling (); + + if (!tracker_seccomp_init ()) + g_assert_not_reached (); + + return do_main (argc, argv); } diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/src/tracker-extract/tracker-main.h tracker-miners-2.3.3.new/src/tracker-extract/tracker-main.h --- tracker-miners-2.3.3.old/src/tracker-extract/tracker-main.h 2020-03-10 05:54:32.670933500 +0800 +++ tracker-miners-2.3.3.new/src/tracker-extract/tracker-main.h 2023-12-08 15:11:34.515259759 +0800 @@ -21,13 +21,8 @@ #ifndef __TRACKER_MAIN_H__ #define __TRACKER_MAIN_H__ -#include "tracker-config.h" - G_BEGIN_DECLS -/* Enables getting the config object from extractors */ -TrackerConfig *tracker_main_get_config (void); - G_END_DECLS #endif /* __TRACKER_MAIN_H__ */ diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/tests/libtracker-extract/tracker-extract-info-test.c tracker-miners-2.3.3.new/tests/libtracker-extract/tracker-extract-info-test.c --- tracker-miners-2.3.3.old/tests/libtracker-extract/tracker-extract-info-test.c 2020-03-10 05:54:32.706934200 +0800 +++ tracker-miners-2.3.3.new/tests/libtracker-extract/tracker-extract-info-test.c 2023-12-08 15:11:34.515259759 +0800 @@ -29,7 +29,7 @@ file = g_file_new_for_path ("./imaginary-file-2"); - info = tracker_extract_info_new (file, "imaginary/mime"); + info = tracker_extract_info_new (file, "imaginary/mime", 100); info_ref = tracker_extract_info_ref (info); g_assert (g_file_equal (file, tracker_extract_info_get_file (info))); @@ -50,7 +50,7 @@ file = g_file_new_for_path ("./imaginary-file"); - info = tracker_extract_info_new (file, "imaginary/mime"); + info = tracker_extract_info_new (file, "imaginary/mime", 100); info_ref = tracker_extract_info_ref (info); tracker_extract_info_unref (info_ref); diff --unified --recursive --text --new-file --color tracker-miners-2.3.3.old/tests/libtracker-extract/tracker-module-manager-test.c tracker-miners-2.3.3.new/tests/libtracker-extract/tracker-module-manager-test.c --- tracker-miners-2.3.3.old/tests/libtracker-extract/tracker-module-manager-test.c 2020-03-10 05:54:32.706934200 +0800 +++ tracker-miners-2.3.3.new/tests/libtracker-extract/tracker-module-manager-test.c 2023-12-08 15:11:34.515259759 +0800 @@ -79,7 +79,6 @@ gchar *used_filename; g_test_init (&argc, &argv, NULL); - tracker_log_init (3, &used_filename); init_module_manager (); g_test_add_func ("/libtracker-extract/module-manager/extract-rules",
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor