diff options
author | monsta <[email protected]> | 2016-06-25 20:00:58 +0300 |
---|---|---|
committer | monsta <[email protected]> | 2016-08-07 10:12:18 +0300 |
commit | 62e506f4d1ba880fb338a0e95daed6864a30c25d (patch) | |
tree | cd24e6137e666e4754c1ceb93f63c29456f7c7b2 /plugins | |
parent | a1fb72a6bbb3ffb07546e02767a1f707a42ddf38 (diff) | |
download | mate-settings-daemon-62e506f4d1ba880fb338a0e95daed6864a30c25d.tar.bz2 mate-settings-daemon-62e506f4d1ba880fb338a0e95daed6864a30c25d.tar.xz |
housekeeping: replace buggy thumb-cleaning code with correct one
also remove defines for default max age and size - we already have
the defaults set in schema, makes no sense to duplicate them here.
early check for -1 value (means "do not clean thumbs") is ported from:
https://git.gnome.org/browse/gnome-settings-daemon/commit?id=12f2121929f048c5cc07cd9c90570310a169b29e
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/housekeeping/msd-housekeeping-manager.c | 69 |
1 files changed, 14 insertions, 55 deletions
diff --git a/plugins/housekeeping/msd-housekeeping-manager.c b/plugins/housekeeping/msd-housekeeping-manager.c index 9418e92..e04f527 100644 --- a/plugins/housekeeping/msd-housekeeping-manager.c +++ b/plugins/housekeeping/msd-housekeeping-manager.c @@ -37,8 +37,6 @@ #define THUMB_CACHE_SCHEMA "org.mate.thumbnail-cache" #define THUMB_CACHE_KEY_AGE "maximum-age" #define THUMB_CACHE_KEY_SIZE "maximum-size" -#define DEFAULT_MAX_AGE 180 /* in Days */ -#define DEFAULT_MAX_SIZE 512 /* in MB */ struct MsdHousekeepingManagerPrivate { guint long_term_cb; @@ -148,50 +146,6 @@ sort_file_mtime (ThumbData *file1, ThumbData *file2) return file1->mtime - file2->mtime; } -static gboolean -int_gsettings_mapping (GVariant *value, - gpointer *result, - gpointer int_ptr) -{ - gint32 key_value = g_variant_get_int32 (value); - - /* NULL value means the "last chance" for us to return a valid value */ - if (value == NULL) { - *result = int_ptr; /* use the supplied default value */ - return TRUE; - } - - /* For either AGE/SIZE keys, -1 disables cleaning. - * A zero value corresponds to an extra-paranoid level of cleaning - */ - if (key_value >= -1) { - *result = &key_value; - return TRUE; - } - - return FALSE; -} - -static int -get_max_age (MsdHousekeepingManager *manager) -{ - int *age = g_settings_get_mapped (manager->priv->settings, - THUMB_CACHE_KEY_AGE, - int_gsettings_mapping, - GINT_TO_POINTER(DEFAULT_MAX_AGE)); - return *age * 24 * 60 * 60; -} - -static int -get_max_size (MsdHousekeepingManager *manager) -{ - int *size = g_settings_get_mapped (manager->priv->settings, - THUMB_CACHE_KEY_SIZE, - int_gsettings_mapping, - GINT_TO_POINTER(DEFAULT_MAX_SIZE)); - return *size * 1024 * 1024; -} - static void purge_thumbnail_cache (MsdHousekeepingManager *manager) { @@ -203,6 +157,13 @@ purge_thumbnail_cache (MsdHousekeepingManager *manager) g_debug ("housekeeping: checking thumbnail cache size and freshness"); + purge_data.max_age = g_settings_get_int (manager->priv->settings, THUMB_CACHE_KEY_AGE) * 24 * 60 * 60; + purge_data.max_size = g_settings_get_int (manager->priv->settings, THUMB_CACHE_KEY_SIZE) * 1024 * 1024; + + /* if both are set to -1, we don't need to read anything */ + if ((purge_data.max_age < 0) && (purge_data.max_size < 0)) + return; + path = g_build_filename (g_get_user_cache_dir (), "thumbnails", "normal", @@ -228,8 +189,6 @@ purge_thumbnail_cache (MsdHousekeepingManager *manager) g_get_current_time (¤t_time); purge_data.now = current_time.tv_sec; - purge_data.max_age = get_max_age (manager); - purge_data.max_size = get_max_size (manager); purge_data.total_size = 0; if (purge_data.max_age >= 0) @@ -325,13 +284,13 @@ msd_housekeeping_manager_stop (MsdHousekeepingManager *manager) g_source_remove (p->long_term_cb); p->long_term_cb = 0; - /* Do a clean-up on shutdown if and only if the size or age - * limits have been set to a paranoid level of cleaning (zero) - */ - if (get_max_age (manager) == 0 || get_max_size (manager) == 0) - { - do_cleanup (manager); - } + /* Do a clean-up on shutdown if and only if the size or age + * limits have been set to a paranoid level of cleaning (zero) + */ + if ((g_settings_get_int (p->settings, THUMB_CACHE_KEY_AGE) == 0) || + (g_settings_get_int (p->settings, THUMB_CACHE_KEY_SIZE) == 0)) { + do_cleanup (manager); + } } g_object_unref (p->settings); |