[gnome-autoar] AutoarExtractor: Fix decompressing archive with legacy encoding filenames



commit b08c420ab0cb5f64ad621ea970fbf23cfe0328b2
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Jul 18 19:29:12 2017 +0200

    AutoarExtractor: Fix decompressing archive with legacy encoding filenames
    
    The archive in question contains filenames in IBM 437 encoding, likely
    generated with an older version of Windows. Convert the filenames to
    UTF-8 before writing the files out to disk to avoid "Invalid argument"
    errors for filesystems which don't like non-UTF-8 encodings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785077

 gnome-autoar/autoar-extractor.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/gnome-autoar/autoar-extractor.c b/gnome-autoar/autoar-extractor.c
index 97dd75d..f1f49cf 100644
--- a/gnome-autoar/autoar-extractor.c
+++ b/gnome-autoar/autoar-extractor.c
@@ -845,13 +845,16 @@ autoar_extractor_get_common_prefix (GList *files,
 
 static GFile*
 autoar_extractor_do_sanitize_pathname (AutoarExtractor *self,
-                                       const char      *pathname)
+                                       const char      *pathname_bytes)
 {
   GFile *extracted_filename;
   gboolean valid_filename;
   g_autofree char *sanitized_pathname;
+  g_autofree char *utf8_pathname;
 
-  extracted_filename = g_file_get_child (self->destination_dir, pathname);
+  utf8_pathname = autoar_common_get_utf8_pathname (pathname_bytes);
+  extracted_filename = g_file_get_child (self->destination_dir,
+                                         utf8_pathname ?  utf8_pathname : pathname_bytes);
 
   valid_filename =
     g_file_equal (extracted_filename, self->destination_dir) ||
@@ -1582,6 +1585,7 @@ autoar_extractor_step_scan_toplevel (AutoarExtractor *self)
 
   while ((r = archive_read_next_header (a, &entry)) == ARCHIVE_OK) {
     const char *pathname;
+    g_autofree char *utf8_pathname = NULL;
 
     if (g_cancellable_is_cancelled (self->cancellable)) {
       archive_read_free (a);
@@ -1598,12 +1602,17 @@ autoar_extractor_step_scan_toplevel (AutoarExtractor *self)
                self->total_files, pathname);
     } else {
       pathname = archive_entry_pathname (entry);
-      g_debug ("autoar_extractor_step_scan_toplevel: %d: pathname = %s",
-               self->total_files, pathname);
+      utf8_pathname = autoar_common_get_utf8_pathname (pathname);
+
+      g_debug ("autoar_extractor_step_scan_toplevel: %d: pathname = %s %s%s",
+               self->total_files, pathname,
+               utf8_pathname ? "utf8 pathname = " :"",
+               utf8_pathname ? utf8_pathname : "");
     }
     self->files_list =
       g_list_prepend (self->files_list,
-                      g_file_get_child (self->output_file, pathname));
+                      g_file_get_child (self->output_file,
+                                        utf8_pathname ? utf8_pathname : pathname));
     self->total_files++;
     self->total_size += archive_entry_size (entry);
     archive_read_data_skip (a);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]