From fd9484a8b84d0be9bd1b279b82288cc8472fda5f Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 4 Apr 2026 16:12:57 +0200 Subject: [PATCH] plug-ins: better error message for file-compressor for specific issues. This is a further improvement, for the specific case which appeared on issue #16160. Basically here for the specific case when we have permission issues, or other similar issues where we fail to either load the input image, or export to the temporary file, we would get more explicit error messages. And this would also show in the stderr output of the in-build-gimp.py script. In particular, when reproducing #16160 permission issue, the build logs now contain this error: GIMP-Error: Opening '/path/to/gimp/gimp-data/images/gimp-splash.xcf.xz' failed: Error creating temporary file '/tmp/gimp/3.2/gimp-temp-1719540.xcf': Permission denied This should better help diagnose similar issues in the future. --- plug-ins/common/file-compressor.c | 107 +++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 25 deletions(-) diff --git a/plug-ins/common/file-compressor.c b/plug-ins/common/file-compressor.c index 42ac83ea62..1b6b512f59 100644 --- a/plug-ins/common/file-compressor.c +++ b/plug-ins/common/file-compressor.c @@ -108,10 +108,11 @@ * that metric, I figure this plug-in is worth about $10,000 USD */ /* But you got it free. Magic of Gnu. */ -typedef gboolean (* LoadFn) (GFile *infile, - GFile *outfile); -typedef gboolean (* SaveFn) (GFile *infile, - GFile *outfile); +typedef gboolean (* LoadFn) (GFile *infile, + GFile *outfile, + GError **error); +typedef gboolean (* SaveFn) (GFile *infile, + GFile *outfile); typedef struct _CompressorEntry CompressorEntry; @@ -194,22 +195,26 @@ static const gchar * find_extension (const CompressorEntry *comp const gchar *filename); static gboolean gzip_load (GFile *infile, - GFile *outfile); + GFile *outfile, + GError **error); static gboolean gzip_export (GFile *infile, GFile *outfile); static gboolean bzip2_load (GFile *infile, - GFile *outfile); + GFile *outfile, + GError **error); static gboolean bzip2_export (GFile *infile, GFile *outfile); static gboolean xz_load (GFile *infile, - GFile *outfile); + GFile *outfile, + GError **error); static gboolean xz_export (GFile *infile, GFile *outfile); static gboolean zip_load (GFile *infile, - GFile *outfile); + GFile *outfile, + GError **error); static goffset get_file_info (GFile *file); @@ -540,7 +545,7 @@ load_image (const CompressorEntry *compressor, /* find a temp name */ tmp_file = gimp_temp_file (ext + 1); - if (! compressor->load_fn (file, tmp_file)) + if (! compressor->load_fn (file, tmp_file, error)) { g_object_unref (tmp_file); *status = GIMP_PDB_EXECUTION_ERROR; @@ -631,8 +636,9 @@ find_extension (const CompressorEntry *compressor, } static gboolean -gzip_load (GFile *infile, - GFile *outfile) +gzip_load (GFile *infile, + GFile *outfile, + GError **error) { gboolean ret; int fd; @@ -647,7 +653,13 @@ gzip_load (GFile *infile, fd = g_open (g_file_peek_path (infile), O_RDONLY | _O_BINARY, 0); if (fd == -1) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error opening file '%s': %s", + g_file_peek_path (infile), + g_strerror (errno)); + goto out; + } in = gzdopen (fd, "rb"); if (! in) @@ -658,7 +670,13 @@ gzip_load (GFile *infile, out = g_fopen (g_file_peek_path (outfile), "wb"); if (! out) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error creating temporary file '%s': %s", + g_file_peek_path (outfile), + g_strerror (errno)); + goto out; + } while (TRUE) { @@ -753,8 +771,9 @@ gzip_export (GFile *infile, } static gboolean -bzip2_load (GFile *infile, - GFile *outfile) +bzip2_load (GFile *infile, + GFile *outfile, + GError **error) { gboolean ret; int fd; @@ -769,7 +788,13 @@ bzip2_load (GFile *infile, fd = g_open (g_file_peek_path (infile), O_RDONLY | _O_BINARY, 0); if (fd == -1) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error opening file '%s': %s", + g_file_peek_path (infile), + g_strerror (errno)); + goto out; + } in = BZ2_bzdopen (fd, "rb"); if (!in) @@ -780,7 +805,13 @@ bzip2_load (GFile *infile, out = g_fopen (g_file_peek_path (outfile), "wb"); if (!out) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error creating temporary file '%s': %s", + g_file_peek_path (outfile), + g_strerror (errno)); + goto out; + } while (TRUE) { @@ -875,8 +906,9 @@ bzip2_export (GFile *infile, } static gboolean -xz_load (GFile *infile, - GFile *outfile) +xz_load (GFile *infile, + GFile *outfile, + GError **error) { gboolean ret; FILE *in; @@ -893,11 +925,23 @@ xz_load (GFile *infile, in = g_fopen (g_file_peek_path (infile), "rb"); if (!in) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error opening file '%s': %s", + g_file_peek_path (infile), + g_strerror (errno)); + goto out; + } out = g_fopen (g_file_peek_path (outfile), "wb"); if (!out) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error creating temporary file '%s': %s", + g_file_peek_path (outfile), + g_strerror (errno)); + goto out; + } if (lzma_stream_decoder (&strm, UINT64_MAX, 0) != LZMA_OK) goto out; @@ -1057,8 +1101,9 @@ xz_export (GFile *infile, } static gboolean -zip_load (GFile *infile, - GFile *outfile) +zip_load (GFile *infile, + GFile *outfile, + GError **error) { gboolean ret; FILE *in; @@ -1073,11 +1118,23 @@ zip_load (GFile *infile, in = g_fopen (g_file_peek_path (infile), "rb"); if (!in) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error opening file '%s': %s", + g_file_peek_path (infile), + g_strerror (errno)); + goto out; + } out = g_fopen (g_file_peek_path (outfile), "wb"); if (! out) - goto out; + { + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Error creating temporary file '%s': %s", + g_file_peek_path (outfile), + g_strerror (errno)); + goto out; + } if ((a = archive_read_new ())) {