From 99d034af6cceb6a170c9022f3261cfcb3a6cade0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Sat, 22 Aug 2020 11:04:26 +0100 Subject: file: Add "date_created" attribute GIO 2.66 introduces support for Linux statx stx_btime.[0] First, let's add support for this attribute in our file models. No user-visible changes yet. [0] https://gitlab.gnome.org/GNOME/glib/-/commit/a396fa9027bf9aaab0697789fe38efec53b09431 --- src/nautilus-file-private.h | 1 + src/nautilus-file.c | 43 ++++++++++++++++++++++++++++++++++++++++--- src/nautilus-file.h | 2 ++ src/nautilus-vfs-file.c | 16 ++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/nautilus-file-private.h b/src/nautilus-file-private.h index ed9725b23..831ed8d44 100644 --- a/src/nautilus-file-private.h +++ b/src/nautilus-file-private.h @@ -67,6 +67,7 @@ struct NautilusFileDetails time_t atime; /* 0 is unknown */ time_t mtime; /* 0 is unknown */ + time_t btime; /* 0 is unknown */ char *symlink_name; diff --git a/src/nautilus-file.c b/src/nautilus-file.c index 88b28c61b..4758ad1d1 100644 --- a/src/nautilus-file.c +++ b/src/nautilus-file.c @@ -144,6 +144,8 @@ static GQuark attribute_name_q, attribute_accessed_date_q, attribute_date_accessed_q, attribute_date_accessed_full_q, + attribute_date_created_q, + attribute_date_created_full_q, attribute_mime_type_q, attribute_size_detail_q, attribute_deep_size_q, @@ -554,6 +556,7 @@ nautilus_file_clear_info (NautilusFile *file) file->details->sort_order = 0; file->details->mtime = 0; file->details->atime = 0; + file->details->btime = 0; file->details->trash_time = 0; file->details->recency = 0; g_free (file->details->symlink_name); @@ -2442,7 +2445,7 @@ update_info_internal (NautilusFile *file, int uid, gid; goffset size; int sort_order; - time_t atime, mtime; + time_t atime, mtime, btime; time_t trash_time; time_t recency; GTimeVal g_trash_time; @@ -2774,6 +2777,7 @@ update_info_internal (NautilusFile *file, atime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS); mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); + btime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED); if (file->details->atime != atime || file->details->mtime != mtime) { @@ -2786,6 +2790,7 @@ update_info_internal (NautilusFile *file, } file->details->atime = atime; file->details->mtime = mtime; + file->details->btime = btime; if (file->details->thumbnail != NULL && file->details->thumbnail_mtime != 0 && @@ -3163,6 +3168,12 @@ get_time (NautilusFile *file, } break; + case NAUTILUS_DATE_TYPE_CREATED: + { + time = file->details->btime; + } + break; + case NAUTILUS_DATE_TYPE_TRASHED: { time = file->details->trash_time; @@ -5384,6 +5395,7 @@ nautilus_file_get_date (NautilusFile *file, g_return_val_if_fail (date_type == NAUTILUS_DATE_TYPE_ACCESSED || date_type == NAUTILUS_DATE_TYPE_MODIFIED + || date_type == NAUTILUS_DATE_TYPE_CREATED || date_type == NAUTILUS_DATE_TYPE_TRASHED || date_type == NAUTILUS_DATE_TYPE_RECENCY, FALSE); @@ -5859,6 +5871,12 @@ nautilus_file_get_atime (NautilusFile *file) return file->details->atime; } +time_t +nautilus_file_get_btime (NautilusFile *file) +{ + return file->details->btime; +} + time_t nautilus_file_get_recency (NautilusFile *file) { @@ -7142,8 +7160,8 @@ nautilus_file_get_deep_directory_count_as_string (NautilusFile *file) * @file: NautilusFile representing the file in question. * @attribute_name: The name of the desired attribute. The currently supported * set includes "name", "type", "detailed_type", "mime_type", "size", "deep_size", "deep_directory_count", - * "deep_file_count", "deep_total_count", "date_modified", "date_accessed", - * "date_modified_full", "date_accessed_full", + * "deep_file_count", "deep_total_count", "date_modified", "date_accessed", "date_created", + * "date_modified_full", "date_accessed_full", "date_created_full", * "owner", "group", "permissions", "octal_permissions", "uri", "where", * "link_target", "volume", "free_space", "selinux_context", "trashed_on", "trashed_on_full", "trashed_orig_path", * "recency" @@ -7232,6 +7250,18 @@ nautilus_file_get_string_attribute_q (NautilusFile *file, NAUTILUS_DATE_TYPE_ACCESSED, NAUTILUS_DATE_FORMAT_FULL); } + if (attribute_q == attribute_date_created_q) + { + return nautilus_file_get_date_as_string (file, + NAUTILUS_DATE_TYPE_CREATED, + NAUTILUS_DATE_FORMAT_REGULAR); + } + if (attribute_q == attribute_date_created_full_q) + { + return nautilus_file_get_date_as_string (file, + NAUTILUS_DATE_TYPE_CREATED, + NAUTILUS_DATE_FORMAT_FULL); + } if (attribute_q == attribute_trashed_on_q) { return nautilus_file_get_date_as_string (file, @@ -7415,6 +7445,11 @@ nautilus_file_get_string_attribute_with_default_q (NautilusFile *file, /* If n/a */ return g_strdup (""); } + if (attribute_q == attribute_date_created_full_q) + { + /* If n/a */ + return g_strdup ("—"); + } /* Fallback, use for both unknown attributes and attributes * for which we have no more appropriate default. @@ -9213,6 +9248,8 @@ nautilus_file_class_init (NautilusFileClass *class) attribute_accessed_date_q = g_quark_from_static_string ("accessed_date"); attribute_date_accessed_q = g_quark_from_static_string ("date_accessed"); attribute_date_accessed_full_q = g_quark_from_static_string ("date_accessed_full"); + attribute_date_created_q = g_quark_from_static_string ("date_created"); + attribute_date_created_full_q = g_quark_from_static_string ("date_created_full"); attribute_mime_type_q = g_quark_from_static_string ("mime_type"); attribute_size_detail_q = g_quark_from_static_string ("size_detail"); attribute_deep_size_q = g_quark_from_static_string ("deep_size"); diff --git a/src/nautilus-file.h b/src/nautilus-file.h index 2164808ca..eb3a1f13f 100644 --- a/src/nautilus-file.h +++ b/src/nautilus-file.h @@ -196,6 +196,7 @@ gboolean nautilus_file_can_get_size (Nautilu goffset nautilus_file_get_size (NautilusFile *file); time_t nautilus_file_get_mtime (NautilusFile *file); time_t nautilus_file_get_atime (NautilusFile *file); +time_t nautilus_file_get_btime (NautilusFile *file); time_t nautilus_file_get_recency (NautilusFile *file); time_t nautilus_file_get_trash_time (NautilusFile *file); GFileType nautilus_file_get_file_type (NautilusFile *file); @@ -529,6 +530,7 @@ struct NautilusFile { typedef enum { NAUTILUS_DATE_TYPE_MODIFIED, NAUTILUS_DATE_TYPE_ACCESSED, + NAUTILUS_DATE_TYPE_CREATED, NAUTILUS_DATE_TYPE_TRASHED, NAUTILUS_DATE_TYPE_RECENCY } NautilusDateType; diff --git a/src/nautilus-vfs-file.c b/src/nautilus-vfs-file.c index 66dff20a2..ccbbc3536 100644 --- a/src/nautilus-vfs-file.c +++ b/src/nautilus-vfs-file.c @@ -225,11 +225,13 @@ vfs_file_get_date (NautilusFile *file, { time_t atime; time_t mtime; + time_t btime; time_t recency; time_t trash_time; atime = nautilus_file_get_atime (file); mtime = nautilus_file_get_mtime (file); + btime = nautilus_file_get_btime (file); recency = nautilus_file_get_recency (file); trash_time = nautilus_file_get_trash_time (file); @@ -263,6 +265,20 @@ vfs_file_get_date (NautilusFile *file, return TRUE; } + case NAUTILUS_DATE_TYPE_CREATED: + { + /* Before we have info on a file, the date is unknown. */ + if (btime == 0) + { + return FALSE; + } + if (date != NULL) + { + *date = btime; + } + return TRUE; + } + case NAUTILUS_DATE_TYPE_TRASHED: { /* Before we have info on a file, the date is unknown. */ -- cgit v1.2.1