summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2019-09-18 12:35:09 +0200
committermonsta <[email protected]>2020-01-09 17:33:26 +0300
commit019f747640edb7d34e17d5bf2fd32d463ff491a0 (patch)
treed297a6cc3f605a5c871cc4714c084d1519372596
parent162d8f8f66d5a5af20d20b1e67dc7bc7960f2cc8 (diff)
downloadengrampa-019f747640edb7d34e17d5bf2fd32d463ff491a0.tar.bz2
engrampa-019f747640edb7d34e17d5bf2fd32d463ff491a0.tar.xz
fr-command-dpkg: fetch dates with strptime
-rw-r--r--src/fr-command-dpkg.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/fr-command-dpkg.c b/src/fr-command-dpkg.c
index 184da01..8c6cd8e 100644
--- a/src/fr-command-dpkg.c
+++ b/src/fr-command-dpkg.c
@@ -20,6 +20,8 @@
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02110-1301, USA.
*/
+#define _XOPEN_SOURCE /* strptime */
+
#include <config.h>
#include <stdlib.h>
#include <string.h>
@@ -33,6 +35,8 @@
#include "fr-command.h"
#include "fr-command-dpkg.h"
+#define LSDPKG_DATE_FORMAT "%Y-%m-%d %H:%M"
+
static void fr_command_dpkg_class_init (FrCommandDpkgClass *class);
static void fr_command_dpkg_init (FrCommand *afile);
static void fr_command_dpkg_finalize (GObject *object);
@@ -41,6 +45,15 @@ static void fr_command_dpkg_finalize (GObject *object);
static FrCommandClass *parent_class = NULL;
+static time_t
+mktime_from_string (const char *time_s)
+{
+ struct tm tm = {0, };
+ tm.tm_isdst = -1;
+ strptime (time_s, LSDPKG_DATE_FORMAT, &tm);
+ return mktime (&tm);
+}
+
static void
process_metadata_line (char *line,
FrCommand *comm)
@@ -87,8 +100,7 @@ process_data_line (char *line,
FileData *fdata;
FrCommand *comm = FR_COMMAND (data);
char **fields;
- char **tmfields;
- struct tm tm = {0, };
+ char *time_s;
const char *name;
g_return_if_fail (line != NULL);
@@ -102,22 +114,12 @@ process_data_line (char *line,
fdata = file_data_new ();
fields = split_line (line, 5);
+
fdata->size = g_ascii_strtoull (fields[2], NULL, 10);
- tmfields = g_strsplit(fields[3], "-", 3);
- if (tmfields[2]) {
- tm.tm_year = atoi (tmfields[0]) - 1900;
- tm.tm_mon = atoi (tmfields[1]);
- tm.tm_mday = atoi (tmfields[2]);
- }
- g_strfreev (tmfields);
- tmfields = g_strsplit (fields[4], ":", 2);
- if (tmfields[1]) {
- tm.tm_hour = atoi (tmfields[0]);
- tm.tm_min = atoi (tmfields[1]);
- }
- g_strfreev (tmfields);
- fdata->modified = mktime (&tm);
- g_strfreev (fields);
+
+ time_s = g_strjoin (" ", fields[3], fields[4], NULL);
+ fdata->modified = mktime_from_string (time_s);
+ g_free (time_s);
name = get_last_field (line, 6);
fields = g_strsplit (name, " -> ", 2);