After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 149572 - Automatic remove file from Trash if it was deleted longer then N days ago
Automatic remove file from Trash if it was deleted longer then N days ago
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: housekeeping
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
: 340706 435213 556413 585910 619408 (view as bug list)
Depends on: 689048
Blocks: 687774
 
 
Reported: 2004-08-07 13:57 UTC by Jaap A. Haitsma
Modified: 2013-03-04 12:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
housekeeping: Add new settings for automatic purging of trash (1.95 KB, patch)
2012-11-25 15:09 UTC, Matthias Clasen
rejected Details | Review
housekeeping: Implement automatic purging of trash:// (12.14 KB, patch)
2012-11-25 15:09 UTC, Matthias Clasen
needs-work Details | Review
housekeeping: Port test to new trash purge api (2.62 KB, patch)
2012-11-25 15:09 UTC, Matthias Clasen
reviewed Details | Review
housekeeping: Add a D-Bus interface (5.98 KB, patch)
2012-11-25 15:10 UTC, Matthias Clasen
reviewed Details | Review
Use the settings from the privacy schema (2.70 KB, patch)
2012-11-25 20:48 UTC, Matthias Clasen
reviewed Details | Review
housekeeping: Implement automatic purging of trash and temp files (12.16 KB, patch)
2012-11-28 06:17 UTC, Matthias Clasen
none Details | Review
bump required gsettings-desktop-schemas version (1.21 KB, patch)
2012-11-28 06:18 UTC, Matthias Clasen
none Details | Review
housekeeping: Add a D-Bus interface (6.09 KB, patch)
2012-11-28 06:18 UTC, Matthias Clasen
none Details | Review
housekeeping: Implement automatic purging of trash and temp files (12.58 KB, patch)
2012-11-30 14:21 UTC, Matthias Clasen
none Details | Review
bump required gsettings-desktop-schemas version (1.21 KB, patch)
2012-11-30 14:22 UTC, Matthias Clasen
none Details | Review
housekeeping: Add a D-Bus interface (6.09 KB, patch)
2012-11-30 14:22 UTC, Matthias Clasen
committed Details | Review
Do the purging asynchronously (12.71 KB, patch)
2012-11-30 14:23 UTC, Matthias Clasen
none Details | Review

Description Jaap A. Haitsma 2004-08-07 13:57:45 UTC
Now I have to manually empty the trash when I run out of disk space. I then
always empty the complete trash (I'm lazy), but sometimes you then delete a file
which you still needed. If I deleted a file e.g. 3 months ago it's very unlikely
that I will need that file again. So it can be automatically deleted
Comment 1 Vincent Noel 2004-08-27 16:59:51 UTC

*** This bug has been marked as a duplicate of 108413 ***
Comment 2 Matthew Paul Thomas (mpt) 2005-11-30 16:40:07 UTC
Not a duplicate. Bug 108413 is about deleting files from the Trash if that 
would free enough space to perform some action. This bug is about deleting 
files from the Trash after some time, regardless of free space.

In <http://mail.gnome.org/archives/nautilus-list/
2005-September/msg00054.html> I described how this could be presented in the 
Trash's Properties window:

   Automatically delete items from the Trash:
   [ Never            :^]

Menu items: "Never" (the default), "After 1 year", "After 3 months", "After 
1 month", "After 1 week", "After 1 day", "When logging out", and 
"Immediately".
Comment 3 Sergej Kotliar 2006-05-05 07:39:49 UTC
*** Bug 340706 has been marked as a duplicate of this bug. ***
Comment 4 jens diemer 2006-05-05 07:59:28 UTC
I think the user sould not set a "timeout". The User should set a size limit! Here my orig. Feature Request:

The user sould set a max size in percent of the partition size. If the trash is
bigger than this max size, it should delete automatic the oldest files. So it
can't fill the partition!
Comment 5 Cosimo Cecchi 2007-12-26 23:36:59 UTC
*** Bug 435213 has been marked as a duplicate of this bug. ***
Comment 6 Cosimo Cecchi 2008-10-18 14:22:55 UTC
*** Bug 556413 has been marked as a duplicate of this bug. ***
Comment 7 A. Walton 2009-06-16 09:40:32 UTC
*** Bug 585910 has been marked as a duplicate of this bug. ***
Comment 8 A. Walton 2010-05-23 15:25:28 UTC
*** Bug 619408 has been marked as a duplicate of this bug. ***
Comment 9 Yann 2010-05-24 04:16:41 UTC
Dear all,

I think we could propose 2 options in the Trash preferences : 
- some people (jens diemer and me) want to be sure that the partition won't be filled by the trash. Now in Gnome 2.30 (Ubuntu 10.04), a warning comes when a partition is nearly full (can someone tell me exactly the condition? and where to modify it?) that proposes to examine the disk, empty the trash or do nothing. So there could be an option to automatically empty the Trash when this condition (e.g. 500Mo left in the partition) is met.
- some people want to delete automatically trashed files after a certain amount of time (e.g. "Never" (the default), "After 1 year", "After 3 months", "After 
1 month", "After 1 week", "After 1 day", "When logging out", and 
"Immediately"). There could be another Trash option for this.
Comment 10 Jean-François Fortin Tam 2011-06-26 04:03:18 UTC
Nautilus devs: should this be reassigned to gnome-control-center's "Privacy and Sharing" component? Maybe it would be more fitting there. It could be set in the control center and then managed by gnome-settings-daemon thanks to the now standardized trash folders...?
Comment 11 Matthias Clasen 2012-11-25 15:09:27 UTC
Created attachment 229815 [details] [review]
housekeeping: Add new settings for automatic purging of trash

This commit adds new settings, 'purge-trash', 'purge-temp-files'
and 'purge-after', which will be used for automatic purging of
trash and temp files as part of the privacy panel implementation.
Comment 12 Matthias Clasen 2012-11-25 15:09:48 UTC
Created attachment 229816 [details] [review]
housekeeping: Implement automatic purging of trash://

This commit reimplements the 'empty trash' functionality not
to rely on nautilus, and adds an 'age' parameter.

We install timeouts that check once every hour and purges
trash and temporary files if they are older than the 'purge-after'
setting allows. The timeouts only act if the 'purge-trash' or
'purge-temp-files' settings are TRUE.
Comment 13 Matthias Clasen 2012-11-25 15:09:59 UTC
Created attachment 229817 [details] [review]
housekeeping: Port test to new trash purge api

With the new gsd_ldsm_purge_trash call, gsd_ldsm_show_empty_trash
has become redundant. Get rid of it.
Comment 14 Matthias Clasen 2012-11-25 15:10:07 UTC
Created attachment 229818 [details] [review]
housekeeping: Add a D-Bus interface

Export EmptyTrash and RemoveTempFiles methods on the bus. These
will be used in the implementation of the privacy panel to allow
on-the-spot purging.
Comment 15 Matthias Clasen 2012-11-25 20:47:43 UTC
On second thought, these settings are better off in the new privacy schema.
Comment 16 Matthias Clasen 2012-11-25 20:48:55 UTC
Created attachment 229836 [details] [review]
Use the settings from the privacy schema
Comment 17 Bastien Nocera 2012-11-27 13:41:52 UTC
Review of attachment 229815 [details] [review]:

As those are in gsettings-desktop-schemas now.
Comment 18 Bastien Nocera 2012-11-27 14:53:15 UTC
Review of attachment 229816 [details] [review]:

::: plugins/housekeeping/gsd-disk-space.c
@@ +226,3 @@
 
+static GDateTime *
+deletion_time_from_string (const gchar *date)

Use g_time_val_from_iso8601() instead, and win!

@@ +334,3 @@
+
+        if (del_children) {
+                enumerator = g_file_enumerate_children (file,

This needs to be made completely async.

@@ +344,3 @@
+                               (info = g_file_enumerator_next_file (enumerator, cancellable, NULL)) != NULL) {
+                                child = g_file_get_child (file, g_file_info_get_name (info));
+                                delete_recursively_by_age (child, cancellable, age, TRUE, g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY);

I don't think you need to go into the directory. The top-level directory is what will have a deletion-date, the rest will not.

@@ +355,3 @@
+        if (!g_cancellable_is_cancelled (cancellable) && del_file) {
+                if (should_purge_file (file, cancellable, age)) {
+                        g_file_delete (file, cancellable, NULL);

Add a dry-run #ifdef, so we can test this without trashing our data.

@@ +929,3 @@
+
+        purge_trash_id = g_timeout_add_seconds (3600, ldsm_purge_trash, NULL);
+        purge_temp_id = g_timeout_add_seconds (3600, ldsm_purge_temp_files, NULL);

In ldsm_purge_trash() and ldsm_purge_temp_files(), i would create a new GDateTime that you can compare each of the file with, rather than creating one for each and every file.

You should also add a way to check for in-flight deletions (with a time change, i think you could have 2 timeouts starting on top of each other).
Comment 19 Bastien Nocera 2012-11-27 14:55:29 UTC
Review of attachment 229817 [details] [review]:

::: plugins/housekeeping/gsd-empty-trash-test.c
@@ +36,3 @@
         loop = g_main_loop_new (NULL, FALSE);
 
+        gsd_ldsm_purge_trash (0);

This should probably use the dry-run mentioned in the previous review.
Comment 20 Bastien Nocera 2012-11-27 15:02:21 UTC
Review of attachment 229818 [details] [review]:

Looks good.
Comment 21 Matthias Clasen 2012-11-27 16:08:32 UTC
Review of attachment 229836 [details] [review]:

::: plugins/housekeeping/gsd-disk-space.c
@@ +890,3 @@
+        purge_trash = g_settings_get_boolean (privacy_settings, SETTINGS_PURGE_TRASH);
+        purge_temp_files = g_settings_get_boolean (privacy_settings, SETTINGS_PURGE_TEMP_FILES);
+        purge_after = g_settings_get_uint (privacy_settings, SETTINGS_PURGE_AFTER);

This needs to be updated for the changed setting names in gsettings-desktop-schemas.
Comment 22 Bastien Nocera 2012-11-27 16:14:52 UTC
Review of attachment 229836 [details] [review]:

::: plugins/housekeeping/gsd-disk-space.c
@@ +962,3 @@
 
+        if (privacy_settings != NULL) {
+                g_object_unref (privacy_settings);

g_clear_object()?
Comment 23 Bastien Nocera 2012-11-27 16:16:25 UTC
Review of attachment 229816 [details] [review]:

::: plugins/housekeeping/gsd-disk-space.c
@@ +303,3 @@
+              }
+
+            ctime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED);

Use g_file_info_get_get_deletion_date() directly here.
Comment 24 Matthias Clasen 2012-11-28 06:17:26 UTC
Created attachment 230060 [details] [review]
housekeeping: Implement automatic purging of trash and temp files
Comment 25 Matthias Clasen 2012-11-28 06:18:10 UTC
Created attachment 230061 [details] [review]
bump required gsettings-desktop-schemas version
Comment 26 Matthias Clasen 2012-11-28 06:18:51 UTC
Created attachment 230062 [details] [review]
housekeeping: Add a D-Bus interface
Comment 27 Matthias Clasen 2012-11-28 06:19:25 UTC
I couldn't get myself to do the async dance tonight.
Comment 28 Matthias Clasen 2012-11-30 14:21:43 UTC
Created attachment 230280 [details] [review]
housekeeping: Implement automatic purging of trash and temp files
Comment 29 Matthias Clasen 2012-11-30 14:22:30 UTC
Created attachment 230281 [details] [review]
bump required gsettings-desktop-schemas version
Comment 30 Matthias Clasen 2012-11-30 14:22:55 UTC
Created attachment 230282 [details] [review]
housekeeping: Add a D-Bus interface
Comment 31 Matthias Clasen 2012-11-30 14:23:22 UTC
Created attachment 230283 [details] [review]
Do the purging asynchronously
Comment 32 Bastien Nocera 2012-12-03 10:04:20 UTC
Attachment 230282 [details] pushed as 491fe91 - housekeeping: Add a D-Bus interface
Comment 33 asterix 2013-03-03 11:22:34 UTC
Having "immediately" as a time option for emptying the trash is not needed as that is the same as permanently delete.
Comment 34 Bastien Nocera 2013-03-04 12:03:37 UTC
(In reply to comment #33)
> Having "immediately" as a time option for emptying the trash is not needed as
> that is the same as permanently delete.

Which isn't offered as an option. The option also control when to purge temporary files.