Esempio n. 1
0
/* This checks relative caches in dir/.thumbnails and
 * removes them if they have no source counterpart.
 */
gint cache_maintain_dir(FileData *dir_fd, gint recursive, gint clear)
{
	GList *list = NULL;
	gchar *cachedir;
	FileData *cachedir_fd;
	gboolean still_have_a_file = FALSE;
	GList *work;

	cachedir = g_build_filename(dir, GQ_CACHE_LOCAL_THUMB, NULL);
	cachedir_fd = file_data_new_simple(cachedir);
	g_free(cachedir);

	filelist_read(cachedir_fd, &list, NULL);
	work = list;

	while (work)
		{
		FileData *fd;
		gchar *source;

		fd = work->data;
		work = work->next;

		source = g_build_filename(dir->path, fd->name, NULL);

		if (clear ||
		    extension_truncate(source, GQ_CACHE_EXT_THUMB) ||
		    extension_truncate(source, GQ_CACHE_EXT_SIM))
			{
			if (!clear && isfile(source))
				{
				still_have_a_file = TRUE;
				}
			else
				{
				if (!unlink_file(fd->path))
					{
					DEBUG_1("Failed to remove cache file %s", fd->path);
					still_have_a_file = TRUE;
					}
				}
			}
		else
			{
			still_have_a_file = TRUE;
			}
		g_free(source);
		}

	filelist_free(list);
	file_data_unref(cachedir_fd);

	if (recursive)
		{
		list = NULL;

		filelist_read(dir_fd, NULL, &list);
		work = list;
		while (work)
			{
			FileData *fd = work->data;
			work = work->next;

			still_have_a_file |= cache_maintain_dir(fd->path, recursive, clear);
			}

		filelist_free(list);
		}

	return still_have_a_file;
}
Esempio n. 2
0
/* This checks relative caches in dir/.thumbnails and
 * removes them if they have no source counterpart.
 */
gint
cache_maintain_dir (CacheType type, const gchar * dir,
		    gint recursive, gint clear)
{
    GList  *list = NULL;
    gchar  *cachedir;
    gint    still_have_a_file = FALSE;
    GList  *work;

    if (type != CACHE_THUMBS)
	return FALSE;

    cachedir = g_strconcat (dir, "/", PORNVIEW_CACHE_DIR, NULL);
    path_list (cachedir, &list, NULL);
    work = list;

    while (work)
    {
	const gchar *path;
	gchar  *source;

	path = work->data;
	work = work->next;
	source = g_strconcat (dir, "/", filename_from_path (path), NULL);

	if (clear || extension_truncate (source, PORNVIEW_CACHE_THUMB_EXT))
	{
	    if (!clear && isfile (source))
	    {
		still_have_a_file = TRUE;
	    }
	    else
	    {
		if (unlink (path) < 0)
		{
		    still_have_a_file = TRUE;
		}
	    }
	}
	else
	{
	    still_have_a_file = TRUE;
	}
	g_free (source);
    }

    path_list_free (list);
    g_free (cachedir);

    if (recursive)
    {
	list = NULL;
	path_list (dir, NULL, &list);
	work = list;

	while (work)
	{
	    const gchar *path = work->data;

	    work = work->next;
	    still_have_a_file |=
		cache_maintain_dir (type, path, recursive, clear);
	}

	path_list_free (list);
    }

    return still_have_a_file;
}