repo: Only delete temp files older than a day
This is somewhat lame, but to do better we need a reliable multiprocess synchronization mechanism. https://bugzilla.gnome.org/show_bug.cgi?id=709115
This commit is contained in:
parent
7b119370a2
commit
f9379b0ce3
|
|
@ -621,18 +621,23 @@ cleanup_tmpdir (OstreeRepo *self,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_unref_object GFileEnumerator *enumerator = NULL;
|
gs_unref_object GFileEnumerator *enumerator = NULL;
|
||||||
|
guint64 curtime_secs;
|
||||||
|
|
||||||
enumerator = g_file_enumerate_children (self->tmp_dir, "standard::name",
|
enumerator = g_file_enumerate_children (self->tmp_dir, "standard::name,time::modified",
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
cancellable,
|
cancellable,
|
||||||
error);
|
error);
|
||||||
if (!enumerator)
|
if (!enumerator)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
curtime_secs = g_get_real_time () / 1000000;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
GFileInfo *file_info;
|
GFileInfo *file_info;
|
||||||
GFile *path;
|
GFile *path;
|
||||||
|
guint64 mtime;
|
||||||
|
guint64 delta;
|
||||||
|
|
||||||
if (!gs_file_enumerator_iterate (enumerator, &file_info, &path,
|
if (!gs_file_enumerator_iterate (enumerator, &file_info, &path,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
|
|
@ -640,8 +645,20 @@ cleanup_tmpdir (OstreeRepo *self,
|
||||||
if (file_info == NULL)
|
if (file_info == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!gs_shutil_rm_rf (path, cancellable, error))
|
mtime = g_file_info_get_attribute_uint64 (file_info, "time::modified");
|
||||||
goto out;
|
if (mtime > curtime_secs)
|
||||||
|
continue;
|
||||||
|
/* Only delete files older than a day. To do better, we would
|
||||||
|
* need to coordinate between multiple processes in a reliable
|
||||||
|
* fashion. See
|
||||||
|
* https://bugzilla.gnome.org/show_bug.cgi?id=709115
|
||||||
|
*/
|
||||||
|
delta = curtime_secs - mtime;
|
||||||
|
if (delta > 60*60*24)
|
||||||
|
{
|
||||||
|
if (!gs_shutil_rm_rf (path, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue