Ejemplo n.º 1
0
static void metadata_legacy_delete(FileData *fd, const gchar *except)
{
	gchar *metadata_path;
	gchar *metadata_pathl;
	if (!fd) return;

	metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
	if (metadata_path && (!except || strcmp(metadata_path, except) != 0))
		{
		metadata_pathl = path_from_utf8(metadata_path);
		unlink(metadata_pathl);
		g_free(metadata_pathl);
		g_free(metadata_path);
		}

#ifdef HAVE_EXIV2
	/* without exiv2: do not delete xmp metadata because we are not able to convert it,
	   just ignore it */
	metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
	if (metadata_path && (!except || strcmp(metadata_path, except) != 0))
		{
		metadata_pathl = path_from_utf8(metadata_path);
		unlink(metadata_pathl);
		g_free(metadata_pathl);
		g_free(metadata_path);
		}
#endif
}
Ejemplo n.º 2
0
void
cache_maint_removed (CacheType type, const gchar * source)
{
    gchar  *buf;

    if (type == CACHE_THUMBS)
	buf = cache_find_location (type, source, PORNVIEW_CACHE_THUMB_EXT);
    else
	buf = cache_find_location (type, source, PORNVIEW_CACHE_COMMENT_EXT);

    cache_file_remove (buf);
    g_free (buf);
}
Ejemplo n.º 3
0
static void cache_maint_moved(FileData *fd)
{
	gchar *base;
	mode_t mode = 0755;
	const gchar *src = fd->change->source;
	const gchar *dest = fd->change->dest;

	if (!src || !dest) return;

	base = cache_get_location(CACHE_TYPE_THUMB, dest, FALSE, &mode);
	if (recursive_mkdir_if_not_exists(base, mode))
		{
		gchar *buf;
		gchar *d;

		buf = cache_find_location(CACHE_TYPE_THUMB, src);
		d = cache_get_location(CACHE_TYPE_THUMB, dest, TRUE, NULL);
		cache_file_move(buf, d);
		g_free(d);
		g_free(buf);

		buf = cache_find_location(CACHE_TYPE_SIM, src);
		d = cache_get_location(CACHE_TYPE_SIM, dest, TRUE, NULL);
		cache_file_move(buf, d);
		g_free(d);
		g_free(buf);
		}
	else
		{
		log_printf("Failed to create cache dir for move %s\n", base);
		}
	g_free(base);

	base = cache_get_location(CACHE_TYPE_METADATA, dest, FALSE, &mode);
	if (recursive_mkdir_if_not_exists(base, mode))
		{
		gchar *buf;
		gchar *d;

		buf = cache_find_location(CACHE_TYPE_METADATA, src);
		d = cache_get_location(CACHE_TYPE_METADATA, dest, TRUE, NULL);
		cache_file_move(buf, d);
		g_free(d);
		g_free(buf);
		}
	g_free(base);

	if (options->thumbnails.enable_caching && options->thumbnails.spec_standard)
		thumb_std_maint_moved(src, dest);
}
Ejemplo n.º 4
0
static void cache_maint_copied(FileData *fd)
{
	gchar *dest_base;
	gchar *src_cache;
	mode_t mode = 0755;

	src_cache = cache_find_location(CACHE_TYPE_METADATA, fd->change->source);
	if (!src_cache) return;

	dest_base = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, FALSE, &mode);
	if (recursive_mkdir_if_not_exists(dest_base, mode))
		{
		gchar *path;

		path = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, TRUE, NULL);
		if (!copy_file(src_cache, path))
			{
			DEBUG_1("failed to copy metadata %s to %s", src_cache, path);
			}
		g_free(path);
		}

	g_free(dest_base);
	g_free(src_cache);
}
Ejemplo n.º 5
0
CacheLoader *cache_loader_new(FileData *fd, CacheDataType load_mask,
			      CacheLoaderDoneFunc done_func, gpointer done_data)
{
	CacheLoader *cl;
	gchar *found;

	if (!fd || !isfile(fd->path)) return NULL;

	cl = g_new0(CacheLoader, 1);
	cl->fd = file_data_ref(fd);

	cl->done_func = done_func;
	cl->done_data = done_data;

	found = cache_find_location(CACHE_TYPE_SIM, cl->fd->path);
	if (found && filetime(found) == filetime(cl->fd->path))
		{
		cl->cd = cache_sim_data_load(found);
		}
	g_free(found);

	if (!cl->cd) cl->cd = cache_sim_data_new();

	cl->todo_mask = load_mask;
	cl->done_mask = CACHE_LOADER_NONE;

	cl->il = NULL;
	cl->idle_id = g_idle_add(cache_loader_idle_cb, cl);

	cl->error = FALSE;

	return cl;
}
Ejemplo n.º 6
0
static void cache_maint_removed(FileData *fd)
{
	gchar *buf;

	buf = cache_find_location(CACHE_TYPE_THUMB, fd->path);
	cache_file_remove(buf);
	g_free(buf);

	buf = cache_find_location(CACHE_TYPE_SIM, fd->path);
	cache_file_remove(buf);
	g_free(buf);

	buf = cache_find_location(CACHE_TYPE_METADATA, fd->path);
	cache_file_remove(buf);
	g_free(buf);

	if (options->thumbnails.enable_caching && options->thumbnails.spec_standard)
		thumb_std_maint_removed(fd->path);
}
Ejemplo n.º 7
0
void
cache_maint_moved (CacheType type, const gchar * src, const gchar * dest)
{
    gchar  *base;
    mode_t  mode = 0755;

    if (!src || !dest)
	return;

    base = cache_get_location (type, dest, FALSE, NULL, &mode);

    if (cache_ensure_dir_exists (base, mode))
    {
	gchar  *buf;
	gchar  *d;

	if (type == CACHE_THUMBS)
	{
	    buf = cache_find_location (type, src, PORNVIEW_CACHE_THUMB_EXT);
	    d = cache_get_location (type, dest, TRUE,
				    PORNVIEW_CACHE_THUMB_EXT, NULL);
	}
	else
	{
	    buf = cache_find_location (type, src, PORNVIEW_CACHE_COMMENT_EXT);
	    d = cache_get_location (type, dest, TRUE,
				    PORNVIEW_CACHE_COMMENT_EXT, NULL);
	}

	cache_file_move (buf, d);
	g_free (d);
	g_free (buf);
    }
    else
	g_free (base);
}
Ejemplo n.º 8
0
static gboolean metadata_legacy_read(FileData *fd, GList **keywords, gchar **comment)
{
	gchar *metadata_path;
	gchar *metadata_pathl;
	gboolean success = FALSE;

	if (!fd) return FALSE;

	metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path);
	if (!metadata_path) return FALSE;

	metadata_pathl = path_from_utf8(metadata_path);

	success = metadata_file_read(metadata_pathl, keywords, comment);

	g_free(metadata_pathl);
	g_free(metadata_path);

	return success;
}
Ejemplo n.º 9
0
gint
thumb_loader_start (ThumbLoader * tl,
		    void (*func_done) (ThumbLoader *, gpointer),
		    gpointer data_done)
{
    gchar  *cache_path = NULL;

    if (!tl || !tl->path)
	return FALSE;

    tl->func_done = func_done;
    tl->data_done = data_done;

    if (conf.enable_thumb_caching)
    {
	cache_path =
	    cache_find_location (CACHE_THUMBS, tl->path,
				 PORNVIEW_CACHE_THUMB_EXT);

	if (cache_path)
	{
	    if (filetime (cache_path) == filetime (tl->path))
	    {
		if (filesize (cache_path) == 0)
		{
		    g_free (cache_path);
		    return FALSE;
		}

	    }
	    else
	    {
		g_free (cache_path);
		cache_path = NULL;
	    }
	}
    }

    if (cache_path)
    {
	thumb_loader_setup (tl, cache_path);
	g_free (cache_path);
	tl->from_cache = TRUE;
    }
    else
    {
	thumb_loader_setup (tl, tl->path);
    }

    if (!image_loader_start (tl->il, cb_thumb_loader_done, tl))
    {
	/*
	 * try from original if cache attempt 
	 */
	if (tl->from_cache)
	{
	    tl->from_cache = FALSE;
	    image_loader_free (tl->il);
	    thumb_loader_setup (tl, tl->path);
	    if (image_loader_start (tl->il, cb_thumb_loader_done, tl))
		return TRUE;
	}
	/*
	 * mark failed thumbnail in cache with 0 byte file 
	 */
	if (conf.enable_thumb_caching)
	{
	    thumb_loader_mark_failure (tl);
	}

	image_loader_free (tl->il);
	tl->il = NULL;
	return FALSE;
    }

    return TRUE;
}