[libdazzle/libdazzle-3-26] reaper: fix age comparison in reaper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle/libdazzle-3-26] reaper: fix age comparison in reaper
- Date: Thu, 11 Jan 2018 01:03:59 +0000 (UTC)
commit 4c969553fb7ccf5017006adb42eb365cd2acc859
Author: Christian Hergert <chergert redhat com>
Date: Mon Nov 20 22:45:43 2017 -0800
reaper: fix age comparison in reaper
src/files/dzl-directory-reaper.c | 23 +++++++++--------------
1 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/src/files/dzl-directory-reaper.c b/src/files/dzl-directory-reaper.c
index 24db850..7a1c527 100644
--- a/src/files/dzl-directory-reaper.c
+++ b/src/files/dzl-directory-reaper.c
@@ -152,18 +152,6 @@ dzl_directory_reaper_new (void)
}
static gboolean
-has_expired (guint64 mtime,
- guint64 min_age)
-{
- guint64 now = g_get_real_time () / G_USEC_PER_SEC;
-
- if (now >= min_age)
- return (now - min_age) >= mtime;
-
- return FALSE;
-}
-
-static gboolean
remove_directory_with_children (GFile *file,
GCancellable *cancellable,
GError **error)
@@ -233,6 +221,7 @@ dzl_directory_reaper_execute_worker (GTask *task,
GCancellable *cancellable)
{
GArray *patterns = task_data;
+ gint64 now = g_get_real_time ();
g_assert (G_IS_TASK (task));
g_assert (DZL_IS_DIRECTORY_REAPER (source_object));
@@ -267,7 +256,10 @@ dzl_directory_reaper_execute_worker (GTask *task,
v64 = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- if (has_expired (v64, p->min_age))
+ /* mtime is in seconds */
+ v64 *= G_USEC_PER_SEC;
+
+ if (v64 < now - p->min_age)
{
if (!g_file_delete (p->file.file, cancellable, &error))
g_warning ("%s", error->message);
@@ -306,7 +298,10 @@ dzl_directory_reaper_execute_worker (GTask *task,
name = g_file_info_get_name (info);
v64 = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- if (has_expired (v64, p->min_age))
+ /* mtime is in seconds */
+ v64 *= G_USEC_PER_SEC;
+
+ if (v64 < now - p->min_age)
{
g_autoptr(GFile) file = g_file_get_child (p->glob.directory, name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]