[gtksourceview/wip/chergert/gsv-gtk4: 86/131] file: remove use of deprecated GTimeVal API
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 86/131] file: remove use of deprecated GTimeVal API
- Date: Wed, 29 Jan 2020 17:24:44 +0000 (UTC)
commit 60b82717599adfab934405e614e7cb94b3871537
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 15 13:49:14 2020 -0800
file: remove use of deprecated GTimeVal API
We can (and should) use gint64 timestamps and GDateTime when possible to
avoid overflow for 2038.
gtksourceview/gtksourcefile-private.h | 10 ++++------
gtksourceview/gtksourcefile.c | 17 ++++++++++-------
gtksourceview/gtksourcefileloader.c | 14 +++++++++++---
gtksourceview/gtksourcefilesaver.c | 23 +++++++++++++++--------
4 files changed, 40 insertions(+), 24 deletions(-)
---
diff --git a/gtksourceview/gtksourcefile-private.h b/gtksourceview/gtksourcefile-private.h
index 68a94ef8..a64d42cc 100644
--- a/gtksourceview/gtksourcefile-private.h
+++ b/gtksourceview/gtksourcefile-private.h
@@ -35,14 +35,12 @@ void _gtk_source_file_set_compression_type (GtkSource
GtkSourceCompressionType
compression_type);
G_GNUC_INTERNAL
GMountOperation *_gtk_source_file_create_mount_operation (GtkSourceFile *file);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_GNUC_INTERNAL
-gboolean _gtk_source_file_get_modification_time (GtkSourceFile *file,
- GTimeVal
*modification_time);
+gboolean _gtk_source_file_get_modification_time (GtkSourceFile *file,
+ gint64 *modification_time);
G_GNUC_INTERNAL
-void _gtk_source_file_set_modification_time (GtkSourceFile *file,
- GTimeVal
modification_time);
-G_GNUC_END_IGNORE_DEPRECATIONS
+void _gtk_source_file_set_modification_time (GtkSourceFile *file,
+ gint64 modification_time);
G_GNUC_INTERNAL
void _gtk_source_file_set_externally_modified (GtkSourceFile *file,
gboolean
externally_modified);
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 212d46b2..934d150e 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -69,7 +69,7 @@ typedef struct
/* Last known modification time of 'location'. The value is updated on a
* file loading or file saving.
*/
- GTimeVal modification_time;
+ gint64 modification_time;
guint modification_time_set : 1;
@@ -467,7 +467,7 @@ _gtk_source_file_create_mount_operation (GtkSourceFile *file)
gboolean
_gtk_source_file_get_modification_time (GtkSourceFile *file,
- GTimeVal *modification_time)
+ gint64 *modification_time)
{
GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
@@ -490,7 +490,7 @@ _gtk_source_file_get_modification_time (GtkSourceFile *file,
void
_gtk_source_file_set_modification_time (GtkSourceFile *file,
- GTimeVal modification_time)
+ gint64 modification_time)
{
GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
@@ -571,18 +571,21 @@ gtk_source_file_check_file_on_disk (GtkSourceFile *file)
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) &&
priv->modification_time_set)
{
- GTimeVal timeval;
+ GDateTime *dt;
+ gint64 mtime;
- g_file_info_get_modification_time (info, &timeval);
+ dt = g_file_info_get_modification_date_time (info);
+ mtime = g_date_time_to_unix (dt);
/* Note that the modification time can even go backwards if the
* user is copying over an old file.
*/
- if (timeval.tv_sec != priv->modification_time.tv_sec ||
- timeval.tv_usec != priv->modification_time.tv_usec)
+ if (mtime != priv->modification_time)
{
priv->externally_modified = TRUE;
}
+
+ g_date_time_unref (dt);
}
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index e6970fe2..8724731a 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -1250,10 +1250,18 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader *loader,
if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
- GTimeVal modification_time;
+ GDateTime *dt;
+ gint64 mtime = 0;
- g_file_info_get_modification_time (task_data->info, &modification_time);
- _gtk_source_file_set_modification_time (loader->file, modification_time);
+ dt = g_file_info_get_modification_date_time (task_data->info);
+
+ if (dt != NULL)
+ {
+ mtime = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
+ }
+
+ _gtk_source_file_set_modification_time (loader->file, mtime);
}
if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 18e87913..426bbba3 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -925,8 +925,8 @@ check_externally_modified_cb (GObject *source_object,
GtkSourceFileSaver *saver;
TaskData *task_data;
GFileInfo *info;
- GTimeVal old_mtime;
- GTimeVal cur_mtime;
+ gint64 old_mtime;
+ gint64 cur_mtime;
GError *error = NULL;
DEBUG ({
@@ -965,10 +965,13 @@ check_externally_modified_cb (GObject *source_object,
info != NULL &&
g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
- g_file_info_get_modification_time (info, &cur_mtime);
+ GDateTime *dt;
- if (old_mtime.tv_sec != cur_mtime.tv_sec ||
- old_mtime.tv_usec != cur_mtime.tv_usec)
+ dt = g_file_info_get_modification_date_time (info);
+ cur_mtime = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
+
+ if (old_mtime != cur_mtime)
{
DEBUG ({
g_print ("The file is externally modified\n");
@@ -1505,10 +1508,14 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
- GTimeVal modification_time;
+ GDateTime *dt;
+ gint64 mtime;
+
+ dt = g_file_info_get_modification_date_time (task_data->info);
+ mtime = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
- g_file_info_get_modification_time (task_data->info, &modification_time);
- _gtk_source_file_set_modification_time (saver->file, modification_time);
+ _gtk_source_file_set_modification_time (saver->file, mtime);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]