[tracker-miners/wip/carlosg/stable-content-urns: 5/7] libtracker-miners-common: Add API to get stable URNs for file content
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/stable-content-urns: 5/7] libtracker-miners-common: Add API to get stable URNs for file content
- Date: Sat, 25 Dec 2021 14:47:02 +0000 (UTC)
commit 910c12bc9c3e383a3dd3446276fb4cd595b0d095
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Dec 15 02:11:21 2021 +0100
libtracker-miners-common: Add API to get stable URNs for file content
This helper function works on top of G_FILE_ATTRIBUTE_ID_FILE which
based on the filesystem ID and inode. This shares the same lifetime
expectancies we have about our own URNs:
- It is unique system-wide.
- It is persistent as long as there are no file content changes
(e.g. persists on attribute updates).
- It is persistent across file moves/renames too.
And extends the benefits a bit:
- It is persistent across reindexes.
- It is a stat() away, no need to insert a blank node and query for its
name.
Add this piece of API that allows to generate one of these new
stable URNs for file content. Optionally, a suffix can be added,
for the cases where there will be multiple content entities for a
file data object (e.g. flac).
src/libtracker-miners-common/tracker-file-utils.c | 32 +++++++++++++++++++++++
src/libtracker-miners-common/tracker-file-utils.h | 3 +++
2 files changed, 35 insertions(+)
---
diff --git a/src/libtracker-miners-common/tracker-file-utils.c
b/src/libtracker-miners-common/tracker-file-utils.c
index 778df49aa..78064e714 100644
--- a/src/libtracker-miners-common/tracker-file-utils.c
+++ b/src/libtracker-miners-common/tracker-file-utils.c
@@ -720,3 +720,35 @@ tracker_filename_casecmp_without_extension (const gchar *a,
return g_ascii_strncasecmp (a, b, len_a) == 0;
}
+
+gchar *
+tracker_file_get_content_identifier (GFile *file,
+ GFileInfo *info,
+ const gchar *suffix)
+{
+ const gchar *id;
+ gchar *str;
+
+ if (info) {
+ g_object_ref (info);
+ } else {
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_ID_FILE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if (!info)
+ return NULL;
+ }
+
+ id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE);
+
+ if (suffix)
+ str = g_strconcat ("urn:fileid:", id, "/", suffix, NULL);
+ else
+ str = g_strconcat ("urn:fileid:", id, NULL);
+
+ g_object_unref (info);
+
+ return str;
+}
diff --git a/src/libtracker-miners-common/tracker-file-utils.h
b/src/libtracker-miners-common/tracker-file-utils.h
index fb4b200f2..f05535a41 100644
--- a/src/libtracker-miners-common/tracker-file-utils.h
+++ b/src/libtracker-miners-common/tracker-file-utils.h
@@ -44,6 +44,9 @@ gboolean tracker_file_is_locked (GFile *file);
gboolean tracker_file_is_hidden (GFile *file);
gint tracker_file_cmp (GFile *file_a,
GFile *file_b);
+gchar * tracker_file_get_content_identifier (GFile *file,
+ GFileInfo *info,
+ const gchar *suffix);
/* Path utils */
gboolean tracker_path_is_in_path (const gchar *path,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]