[gimp] Avoid use of temporary files for accessing remote files
- From: Sven Neumann <neo src gnome org>
- To: svn-commits-list gnome org
- Subject: [gimp] Avoid use of temporary files for accessing remote files
- Date: Tue, 21 Apr 2009 11:51:02 -0400 (EDT)
commit 6fa2ece547efa1ad515648419f1444ce0b1e948a
Author: Sven Neumann <s neumann phase-zero de>
Date: Tue Apr 21 17:48:17 2009 +0200
Avoid use of temporary files for accessing remote files
When using GIO/GVFS, remote files may have a local representation
provided by a FUSE mount. Try to detect this and access the file
directly instead of using a temporary file. Fallback to the old
behavior of using temporary files if GIO can't give us a local path
to the file.
---
plug-ins/file-uri/uri-backend-gvfs.c | 48 +++++++++++++++++++++++---
plug-ins/file-uri/uri-backend-libcurl.c | 7 ++++
plug-ins/file-uri/uri-backend-wget.c | 7 ++++
plug-ins/file-uri/uri-backend.h | 2 +
plug-ins/file-uri/uri.c | 56 +++++++++++++++++++++----------
5 files changed, 96 insertions(+), 24 deletions(-)
diff --git a/plug-ins/file-uri/uri-backend-gvfs.c b/plug-ins/file-uri/uri-backend-gvfs.c
index 9554371..55cfb78 100644
--- a/plug-ins/file-uri/uri-backend-gvfs.c
+++ b/plug-ins/file-uri/uri-backend-gvfs.c
@@ -39,12 +39,14 @@ typedef enum
} Mode;
-static gchar * get_protocols (void);
-static gboolean copy_uri (const gchar *src_uri,
- const gchar *dest_uri,
- Mode mode,
- GimpRunMode run_mode,
- GError **error);
+static gchar * get_protocols (void);
+static gboolean copy_uri (const gchar *src_uri,
+ const gchar *dest_uri,
+ Mode mode,
+ GimpRunMode run_mode,
+ GError **error);
+static gboolean mount_enclosing_volume (GFile *file,
+ GError **error);
static gchar *supported_protocols = NULL;
@@ -138,6 +140,40 @@ uri_backend_save_image (const gchar *uri,
return FALSE;
}
+gchar *
+uri_backend_map_image (const gchar *uri,
+ GimpRunMode run_mode)
+{
+ GFile *file = g_file_new_for_uri (uri);
+ gchar *path = NULL;
+ gboolean success = TRUE;
+
+ if (! file)
+ return NULL;
+
+ if (run_mode == GIMP_RUN_INTERACTIVE)
+ {
+ GError *error = NULL;
+
+ if (! mount_enclosing_volume (file, &error))
+ {
+
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_ALREADY_MOUNTED)
+ success = TRUE;
+
+ g_error_free (error);
+ }
+ }
+
+ if (success)
+ path = g_file_get_path (file);
+
+ g_object_unref (file);
+
+ return path;
+}
+
/* private functions */
diff --git a/plug-ins/file-uri/uri-backend-libcurl.c b/plug-ins/file-uri/uri-backend-libcurl.c
index 05de944..5632235 100644
--- a/plug-ins/file-uri/uri-backend-libcurl.c
+++ b/plug-ins/file-uri/uri-backend-libcurl.c
@@ -223,3 +223,10 @@ uri_backend_save_image (const gchar *uri,
return FALSE;
}
+
+gchar *
+uri_backend_map_image (const gchar *uri,
+ GimpRunMode run_mode)
+{
+ return NULL;
+}
diff --git a/plug-ins/file-uri/uri-backend-wget.c b/plug-ins/file-uri/uri-backend-wget.c
index 0cfc844..56bf75b 100644
--- a/plug-ins/file-uri/uri-backend-wget.c
+++ b/plug-ins/file-uri/uri-backend-wget.c
@@ -386,3 +386,10 @@ uri_backend_save_image (const gchar *uri,
return FALSE;
}
+
+gchar *
+uri_backend_map_image (const gchar *uri,
+ GimpRunMode run_mode)
+{
+ return NULL;
+}
diff --git a/plug-ins/file-uri/uri-backend.h b/plug-ins/file-uri/uri-backend.h
index b116cc4..1f634a1 100644
--- a/plug-ins/file-uri/uri-backend.h
+++ b/plug-ins/file-uri/uri-backend.h
@@ -39,6 +39,8 @@ gboolean uri_backend_save_image (const gchar *uri,
const gchar *tmpname,
GimpRunMode run_mode,
GError **error);
+gchar * uri_backend_map_image (const gchar *uri,
+ GimpRunMode run_mode);
#endif /* __URI_BACKEND_H__ */
diff --git a/plug-ins/file-uri/uri.c b/plug-ins/file-uri/uri.c
index c84ef7e..e458001 100644
--- a/plug-ins/file-uri/uri.c
+++ b/plug-ins/file-uri/uri.c
@@ -234,28 +234,40 @@ load_image (const gchar *uri,
gchar *tmpname = NULL;
gint32 image_ID = -1;
gboolean name_image = FALSE;
+ gboolean mapped;
- tmpname = get_temp_name (uri, &name_image);
+ tmpname = uri_backend_map_image (uri, run_mode);
- if (uri_backend_load_image (uri, tmpname, run_mode, error))
+ if (tmpname)
{
- image_ID = gimp_file_load (run_mode, tmpname, tmpname);
+ mapped = TRUE;
+ }
+ else
+ {
+ tmpname = get_temp_name (uri, &name_image);
- if (image_ID != -1)
- {
- if (name_image)
- gimp_image_set_filename (image_ID, uri);
- else
- gimp_image_set_filename (image_ID, "");
- }
+ if (! uri_backend_load_image (uri, tmpname, run_mode, error))
+ return -1;
+ }
+
+ image_ID = gimp_file_load (run_mode, tmpname, tmpname);
+
+ if (image_ID != -1)
+ {
+ if (mapped || name_image)
+ gimp_image_set_filename (image_ID, uri);
else
- {
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "%s", gimp_get_pdb_error ());
- }
+ gimp_image_set_filename (image_ID, "");
}
+ else
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ "%s", gimp_get_pdb_error ());
+ }
+
+ if (! mapped)
+ g_unlink (tmpname);
- g_unlink (tmpname);
g_free (tmpname);
return image_ID;
@@ -270,8 +282,14 @@ save_image (const gchar *uri,
{
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
gchar *tmpname;
+ gboolean mapped;
- tmpname = get_temp_name (uri, NULL);
+ tmpname = uri_backend_map_image (uri, run_mode);
+
+ if (tmpname)
+ mapped = TRUE;
+ else
+ tmpname = get_temp_name (uri, NULL);
if (gimp_file_save (run_mode,
image_ID,
@@ -279,7 +297,7 @@ save_image (const gchar *uri,
tmpname,
tmpname) && valid_file (tmpname))
{
- if (uri_backend_save_image (uri, tmpname, run_mode, error))
+ if (mapped || uri_backend_save_image (uri, tmpname, run_mode, error))
{
status = GIMP_PDB_SUCCESS;
}
@@ -290,7 +308,9 @@ save_image (const gchar *uri,
"%s", gimp_get_pdb_error ());
}
- g_unlink (tmpname);
+ if (! mapped)
+ g_unlink (tmpname);
+
g_free (tmpname);
return status;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]