[goffice] go-file: add function to get modtime from a uri.



commit d9425d60eba53112046badcd8be214d1932b89fa
Author: Morten Welinder <terra gnome org>
Date:   Sun Mar 25 15:46:26 2018 -0400

    go-file: add function to get modtime from a uri.

 ChangeLog               |    4 ++++
 goffice/utils/go-file.c |   32 ++++++++++++++++++++++++++++++++
 goffice/utils/go-file.h |    2 ++
 3 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8a0e54b..fbe9f06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-03-25  Morten Welinder  <terra gnome org>
+
+       * goffice/utils/go-file.c (go_file_get_modtime): New function.
+
 2018-03-14  Morten Welinder  <terra gnome org>
 
        * goffice/math/go-quad.c (go_quad_start): Allocate memory before
diff --git a/goffice/utils/go-file.c b/goffice/utils/go-file.c
index f45c36c..4229828 100644
--- a/goffice/utils/go-file.c
+++ b/goffice/utils/go-file.c
@@ -969,6 +969,38 @@ go_file_get_date_changed (char const *uri)
        return go_file_get_date (uri, GO_FILE_DATE_TYPE_CHANGED);
 }
 
+/**
+ * go_file_get_modtime:
+ * @uri: The uri
+ *
+ * Determine the last modification time of @uri.
+ *
+ * Returns: (transfer full): the modification time of the file, or %NULL
+ * if it could not be determined.
+ **/
+GDateTime *
+go_file_get_modtime (char const *uri)
+{
+       GDateTime *modtime = NULL;
+       GFile *file = g_file_new_for_uri (uri);
+       GFileInfo *info;
+
+       info = g_file_query_info (file,
+                                 G_FILE_ATTRIBUTE_TIME_MODIFIED ","
+                                 G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
+                                 G_FILE_QUERY_INFO_NONE, NULL, NULL);
+       if (info) {
+               GTimeVal tv;
+               g_file_info_get_modification_time (info, &tv);
+               modtime = g_date_time_new_from_timeval_utc (&tv);
+               g_object_unref (info);
+       }
+
+       g_object_unref (file);
+
+       return modtime;
+}
+
 /* ------------------------------------------------------------------------- */
 
 /**
diff --git a/goffice/utils/go-file.h b/goffice/utils/go-file.h
index a8dc3a3..3a058a1 100644
--- a/goffice/utils/go-file.h
+++ b/goffice/utils/go-file.h
@@ -86,6 +86,8 @@ GType go_file_permissions_get_type (void);
 GOFilePermissions *go_get_file_permissions (char const *uri);
 void go_set_file_permissions (char const *uri, GOFilePermissions * file_permissions);
 
+GDateTime *go_file_get_modtime   (char const *uri);
+
 time_t go_file_get_date_accessed (char const *uri);
 time_t go_file_get_date_modified (char const *uri);
 time_t go_file_get_date_changed  (char const *uri);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]