Exemple #1
0
/* This checks all files in ~/GQ_RC_DIR/thumbnails and
 * removes them if thay have no source counterpart.
 * (this assumes all cache files have an extension of 4 chars including '.')
 */
gint cache_maintain_home_dir(const gchar *dir, gint recursive, gint clear)
{
	gchar *base;
	gint base_length;
	GList *dlist = NULL;
	FileData *dir_fd;
	GList *flist = NULL;
	gboolean still_have_a_file = FALSE;

	DEBUG_1("maintainance check: %s", dir);

	base_length = strlen(homedir()) + strlen("/") + strlen(GQ_CACHE_RC_THUMB);
	base = g_strconcat(homedir(), "/", GQ_CACHE_RC_THUMB, dir, NULL);
	dir_fd = file_data_new_simple(base);
	g_free(base);

	if (filelist_read(dir_fd, &flist, &dlist))
		{
		GList *work;

		work = dlist;
		while (work)
			{
			FileData *fd = work->data;
			if (recursive && strlen(fd->path) > base_length &&
			    !cache_maintain_home_dir(fd->path + base_length, recursive, clear))
				{
				DEBUG_1("Deleting thumb dir: %s", fd->path);
				if (!rmdir_utf8(fd->path))
					{
					log_printf("Unable to delete dir: %s\n", fd->path);
					}
				}
			else
				{
				still_have_a_file = TRUE;
				}
			work = work->next;
			}

		work = flist;
		while (work)
			{
			FileData *fd = work->data;
			gchar *path = g_strdup(fd->path);
			gchar *dot;

			dot = extension_find_dot(path);

			if (dot) *dot = '\0';
			if (clear ||
			    (strlen(path) > base_length && !isfile(path + base_length)) )
				{
				if (dot) *dot = '.';
				if (!unlink_file(path)) log_printf("failed to delete:%s\n", path);
				}
			else
				{
				still_have_a_file = TRUE;
				}
			g_free(path);

			work = work->next;
			}
		}

	filelist_free(dlist);
	filelist_free(flist);
	file_data_unref(dir_fd);

	return still_have_a_file;
}
Exemple #2
0
int
cache_maintain_home_dir (CacheType type, const gchar * dir,
			 gint recursive, gint clear)
{
    gchar  *base;
    gint    base_length;
    GList  *dlist = NULL;
    GList  *flist = NULL;
    gint    still_have_a_file = FALSE;

    if (type == CACHE_THUMBS)
    {
	base_length =
	    strlen (home_dir ()) + strlen ("/") +
	    strlen (PORNVIEW_RC_DIR_THUMBS);
	base =
	    g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, dir, NULL);
    }
    else
    {
	base_length =
	    strlen (home_dir ()) + strlen ("/") +
	    strlen (PORNVIEW_RC_DIR_COMMENTS);
	base =
	    g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, dir,
			 NULL);
    }

    if (path_list (base, &flist, &dlist))
    {
	GList  *work;
	work = dlist;
	while (work)
	{
	    gchar  *path = work->data;
	    if (recursive && strlen (path) > base_length &&
		!cache_maintain_home_dir (type, path + base_length,
					  recursive, clear))
	    {
		if (rmdir (path) < 0)
		{
		    printf ("Unable to delete dir: %s\n", path);
		}
	    }
	    else
	    {
		still_have_a_file = TRUE;
	    }
	    work = work->next;
	}

	work = flist;

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

	    dot = extension_find_dot (path);

	    if (dot)
		*dot = '\0';

	    if (clear ||
		(strlen (path) > base_length && !isfile (path + base_length)))
	    {
		if (dot)
		    *dot = '.';

		if (unlink (path) < 0)
		    printf ("failed to delete:%s\n", path);
	    }
	    else
	    {
		still_have_a_file = TRUE;
	    }

	    work = work->next;
	}
    }

    path_list_free (dlist);
    path_list_free (flist);
    g_free (base);

    return still_have_a_file;
}