1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

file: Make get_date() method non-polymorphic

It was born as a virtual method with 2 implementations: NautilusVfsFile
and NautilusTrashFile: commit e82bab8c49

Nowadays only the NautilusVfsFile implements it anyway, so, rather than
leaving it undefined for other subclasses it's best to move the
implementation to the parent class and drop the vfunc.

An undefined virtual method obviously can cause problems. A crash
can be reproduced through FileManager1 D-Bus method ShowItemProperties
with the parameters (["x-nautilus-search://0/"],""). We are lucky this
probably never happens under regular usage.
This commit is contained in:
António Fernandes 2024-05-25 19:01:15 +01:00
parent c7d515942b
commit ce35cd2441
3 changed files with 47 additions and 61 deletions

View File

@ -4918,13 +4918,6 @@ GDateTime *
nautilus_file_get_date (NautilusFile *file,
NautilusDateType date_type)
{
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);
if (file == NULL)
{
return NULL;
@ -4932,7 +4925,53 @@ nautilus_file_get_date (NautilusFile *file,
g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_date (file, date_type);
time_t file_time_raw = 0;
switch (date_type)
{
case NAUTILUS_DATE_TYPE_ACCESSED:
{
file_time_raw = nautilus_file_get_atime (file);
}
break;
case NAUTILUS_DATE_TYPE_MODIFIED:
{
file_time_raw = nautilus_file_get_mtime (file);
}
break;
case NAUTILUS_DATE_TYPE_CREATED:
{
file_time_raw = nautilus_file_get_btime (file);
}
break;
case NAUTILUS_DATE_TYPE_TRASHED:
{
file_time_raw = nautilus_file_get_trash_time (file);
}
break;
case NAUTILUS_DATE_TYPE_RECENCY:
{
file_time_raw = nautilus_file_get_recency (file);
}
break;
default:
{
g_return_val_if_reached (NULL);
}
}
/* Before we have info on a file, the date is unknown. */
if (file_time_raw == 0)
{
return NULL;
}
return g_date_time_new_from_unix_local (file_time_raw);
}
static char *

View File

@ -523,8 +523,6 @@ typedef struct {
guint *file_count,
guint *unreadable_directory_count,
goffset *total_size);
GDateTime * (* get_date) (NautilusFile *file,
NautilusDateType type);
char * (* get_where_string) (NautilusFile *file);
void (* set_metadata) (NautilusFile *file,

View File

@ -223,56 +223,6 @@ vfs_file_set_metadata_as_list (NautilusFile *file,
nautilus_file_ref (file));
}
static GDateTime *
vfs_file_get_date (NautilusFile *file,
NautilusDateType date_type)
{
time_t file_time_raw = 0;
switch (date_type)
{
case NAUTILUS_DATE_TYPE_ACCESSED:
{
file_time_raw = nautilus_file_get_atime (file);
}
break;
case NAUTILUS_DATE_TYPE_MODIFIED:
{
file_time_raw = nautilus_file_get_mtime (file);
}
break;
case NAUTILUS_DATE_TYPE_CREATED:
{
file_time_raw = nautilus_file_get_btime (file);
}
break;
case NAUTILUS_DATE_TYPE_TRASHED:
{
file_time_raw = nautilus_file_get_trash_time (file);
}
break;
case NAUTILUS_DATE_TYPE_RECENCY:
{
file_time_raw = nautilus_file_get_recency (file);
}
break;
}
/* Before we have info on a file, the date is unknown. */
if (file_time_raw == 0)
{
return NULL;
}
else
{
return g_date_time_new_from_unix_local (file_time_raw);
}
}
static char *
vfs_file_get_where_string (NautilusFile *file)
{
@ -677,7 +627,6 @@ nautilus_vfs_file_class_init (NautilusVFSFileClass *klass)
file_class->call_when_ready = vfs_file_call_when_ready;
file_class->cancel_call_when_ready = vfs_file_cancel_call_when_ready;
file_class->check_if_ready = vfs_file_check_if_ready;
file_class->get_date = vfs_file_get_date;
file_class->get_where_string = vfs_file_get_where_string;
file_class->set_metadata = vfs_file_set_metadata;
file_class->set_metadata_as_list = vfs_file_set_metadata_as_list;