Commit 88caa4a4 authored by Jehan's avatar Jehan Committed by Øyvind "pippin" Kolås

Bug 690509 - gegl-tile-backend: free disk space when finalizing a tile backend which swaps to disk.

gegl_tile_backend_unlink_swap() written for this purpose and now used
on the 3 currently existing backends which may swap to disk.
Accessorily I ensure any swap path from GEGL config does not end with
a directory separator, to ensure proper string comparison, even when
provided by the user through environment variable.
parent 5f6cbc7c
......@@ -954,7 +954,10 @@ gegl_tile_backend_file_finalize (GObject *object)
gegl_tile_backend_file_free_free_list (self);
if (self->path)
g_free (self->path);
{
gegl_tile_backend_unlink_swap (self->path);
g_free (self->path);
}
if (self->monitor)
g_object_unref (self->monitor);
......
......@@ -861,7 +861,10 @@ gegl_tile_backend_file_finalize (GObject *object)
}
if (self->path)
g_free (self->path);
{
gegl_tile_backend_unlink_swap (self->path);
g_free (self->path);
}
if (self->monitor)
g_object_unref (self->monitor);
......
......@@ -676,7 +676,10 @@ gegl_tile_backend_file_finalize (GObject *object)
}
if (self->path)
g_free (self->path);
{
gegl_tile_backend_unlink_swap (self->path);
g_free (self->path);
}
if (self->monitor)
g_object_unref (self->monitor);
......
......@@ -21,11 +21,13 @@
#include <babl/babl.h>
#include <glib-object.h>
#include <glib/gstdio.h>
#include "gegl-buffer-types.h"
#include "gegl-buffer-private.h"
#include "gegl-tile-source.h"
#include "gegl-tile-backend.h"
#include "gegl-config.h"
G_DEFINE_TYPE (GeglTileBackend, gegl_tile_backend, GEGL_TYPE_TILE_SOURCE)
......@@ -207,3 +209,16 @@ gegl_tile_backend_peek_storage (GeglTileBackend *backend)
{
return backend->priv->storage;
}
void
gegl_tile_backend_unlink_swap (gchar *path)
{
gchar *dirname = g_path_get_dirname (path);
/* Ensure we delete only files in our known swap directory for safety. */
if (g_file_test (path, G_FILE_TEST_EXISTS) &&
g_strcmp0 (dirname, gegl_config()->swap) == 0)
g_unlink (path);
g_free (dirname);
}
......@@ -66,6 +66,18 @@ GeglRectangle gegl_tile_backend_get_extent (GeglTileBackend *tile_backend);
GType gegl_tile_backend_get_type (void) G_GNUC_CONST;
/**
* gegl_tile_backend_unlink_swap:
* @path: the path where the gegl tile backend has swapped.
*
* Delete a swap file from disk. This must be used by tile backends which may
* swap to disk under certain circonstances.
*
* For safety, this function will check that the swap file is in the swap
* directory before deletion but it won't perform any other check.
*/
void gegl_tile_backend_unlink_swap (gchar *path);
G_END_DECLS
#endif
......@@ -109,7 +109,13 @@ gegl_swap_dir (void)
if (g_str_equal (g_getenv ("GEGL_SWAP"), "RAM"))
swapdir = NULL;
else
swapdir = g_strdup (g_getenv ("GEGL_SWAP"));
{
swapdir = g_strstrip (g_strdup (g_getenv ("GEGL_SWAP")));
/* Remove any trailing separator, unless the path is only made of a leading separator. */
while (strlen (swapdir) > strlen (G_DIR_SEPARATOR_S) && g_str_has_suffix (swapdir, G_DIR_SEPARATOR_S))
swapdir[strlen (swapdir) - strlen (G_DIR_SEPARATOR_S)] = '\0';
}
}
else
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment