From 1107d0f7af455c5ca23fd3c619f5bd6ea7d11e2f Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 4 Apr 2026 17:36:29 +0200 Subject: [PATCH] app, pdb, plug-ins: improve error feedback for gimp_temp_file(). It is not a fix yet for #14681 but would provide nicer and earlier error when a call to gimp_temp_file() fails, which may happen in some cases. E.g. if the temp directory doesn't exist and we fail to create it. As a test, if I delete /tmp/gimp/3.2/ and give root ownership to /tmp/gimp/, now the error when opening our gimp-splash.xcf.xz is: GIMP-Error: Opening '/path/to/gimp/gimp-data/images/gimp-splash.xcf.xz' failed: Error creating directory /tmp/gimp/3.2: Permission denied --- app/core/gimp.c | 20 ++++++++++++++++---- app/core/gimp.h | 3 ++- app/file/file-remote.c | 4 ++-- app/pdb/gimp-cmds.c | 3 ++- pdb/groups/gimp.pdb | 3 ++- plug-ins/common/file-compressor.c | 13 +++++++++++++ 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/core/gimp.c b/app/core/gimp.c index 9db4718b37..bd1c21a773 100644 --- a/app/core/gimp.c +++ b/app/core/gimp.c @@ -1273,8 +1273,9 @@ gimp_image_opened (Gimp *gimp, } GFile * -gimp_get_temp_file (Gimp *gimp, - const gchar *extension) +gimp_get_temp_file (Gimp *gimp, + const gchar *extension, + GError **error) { static gint id = 0; static gint pid; @@ -1293,13 +1294,24 @@ gimp_get_temp_file (Gimp *gimp, basename = g_strdup_printf ("gimp-temp-%d%d", pid, id++); dir = gimp_file_new_for_config_path (GIMP_GEGL_CONFIG (gimp->config)->temp_path, - NULL); + error); + if (dir == NULL) + { + g_free (basename); + return NULL; + } + if (! g_file_query_exists (dir, NULL)) { /* Try to make the temp directory if it doesn't exist. * Ignore any error. */ - g_file_make_directory_with_parents (dir, NULL, NULL); + if (! g_file_make_directory_with_parents (dir, NULL, error)) + { + g_free (basename); + g_object_unref (dir); + return NULL; + } } file = g_file_get_child (dir, basename); g_free (basename); diff --git a/app/core/gimp.h b/app/core/gimp.h index 514abc76d2..4cf1676253 100644 --- a/app/core/gimp.h +++ b/app/core/gimp.h @@ -256,7 +256,8 @@ void gimp_image_opened (Gimp *gimp, GFile *file); GFile * gimp_get_temp_file (Gimp *gimp, - const gchar *extension); + const gchar *extension, + GError **error); GimpDataFactory * gimp_get_data_factory (Gimp *gimp, diff --git a/app/file/file-remote.c b/app/file/file-remote.c index 498115afe0..598ccc428f 100644 --- a/app/file/file-remote.c +++ b/app/file/file-remote.c @@ -258,13 +258,13 @@ file_remote_get_temp_file (Gimp *gimp, const gchar *ext = strchr (basename, '.'); if (ext && strlen (ext)) - temp_file = gimp_get_temp_file (gimp, ext + 1); + temp_file = gimp_get_temp_file (gimp, ext + 1, NULL); g_free (basename); } if (! temp_file) - temp_file = gimp_get_temp_file (gimp, "xxx"); + temp_file = gimp_get_temp_file (gimp, "xxx", NULL); return temp_file; } diff --git a/app/pdb/gimp-cmds.c b/app/pdb/gimp-cmds.c index b25b01a91c..cf1d87ec75 100644 --- a/app/pdb/gimp-cmds.c +++ b/app/pdb/gimp-cmds.c @@ -219,7 +219,8 @@ temp_file_invoker (GimpProcedure *procedure, if (success) { - file = gimp_get_temp_file (gimp, extension); + file = gimp_get_temp_file (gimp, extension, error); + success = (file != NULL); } return_vals = gimp_procedure_get_return_values (procedure, success, diff --git a/pdb/groups/gimp.pdb b/pdb/groups/gimp.pdb index 9c22d2f46b..18ec4eb980 100644 --- a/pdb/groups/gimp.pdb +++ b/pdb/groups/gimp.pdb @@ -220,7 +220,8 @@ HELP %invoke = ( code => <<'CODE' { - file = gimp_get_temp_file (gimp, extension); + file = gimp_get_temp_file (gimp, extension, error); + success = (file != NULL); } CODE ); diff --git a/plug-ins/common/file-compressor.c b/plug-ins/common/file-compressor.c index 1b6b512f59..b3847a94f9 100644 --- a/plug-ins/common/file-compressor.c +++ b/plug-ins/common/file-compressor.c @@ -486,6 +486,12 @@ export_image (const CompressorEntry *compressor, /* get a temp name with the right extension and save into it. */ tmp_file = gimp_temp_file (ext + 1); + if (tmp_file == NULL) + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "%s", gimp_pdb_get_last_error (gimp_get_pdb ())); + return gimp_pdb_get_last_status (gimp_get_pdb ()); + } if (! (gimp_file_save (run_mode, image, tmp_file, options) && valid_file (tmp_file))) @@ -544,6 +550,13 @@ load_image (const CompressorEntry *compressor, /* find a temp name */ tmp_file = gimp_temp_file (ext + 1); + if (tmp_file == NULL) + { + *status = gimp_pdb_get_last_status (gimp_get_pdb ()); + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "%s", gimp_pdb_get_last_error (gimp_get_pdb ())); + return NULL; + } if (! compressor->load_fn (file, tmp_file, error)) {