[evince] comics: Fix reading CBZ files created on macOS



commit 7b4ff77e7582241bfd25bed741d493d21e73db3c
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Jan 21 16:19:08 2018 +0100

    comics: Fix reading CBZ files created on macOS
    
    macOS' builtin ZIP file format support will add AppleDouble files to the
    archives in order to store information that would otherwise be stored in
    extended attributes or resource forks, in a way that's unlikely to be
    meddled with by applications that don't know how to handle this
    metadata.
    
    But when we store images in such a ZIP file, we'll end up with files
    named "__MACOSX/dirname/._page0001.JPG" for example, which our current
    code will interpret as being images, and thus pages in our comic.
    They're not. As the AppleDouble files always have the "._" prefix,
    ignore those.
    
    See https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats
    
    https://bugzilla.gnome.org/show_bug.cgi?id=792754

 backend/comics/comics-document.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c
index 0fec236..3c21622 100644
--- a/backend/comics/comics-document.c
+++ b/backend/comics/comics-document.c
@@ -79,6 +79,25 @@ has_supported_extension (const char *name,
        return ret;
 }
 
+#define APPLE_DOUBLE_PREFIX "._"
+static gboolean
+is_apple_double (const char *name)
+{
+       char *basename;
+       gboolean ret = FALSE;
+
+       basename = g_path_get_basename (name);
+       if (basename == NULL) {
+               g_debug ("Filename '%s' doesn't have a basename?", name);
+               return ret;
+       }
+
+       ret = g_str_has_prefix (basename, APPLE_DOUBLE_PREFIX);
+       g_free (basename);
+
+       return ret;
+}
+
 static GPtrArray *
 comics_document_list (ComicsDocument  *comics_document,
                      GError         **error)
@@ -125,6 +144,12 @@ comics_document_list (ComicsDocument  *comics_document,
                }
 
                name = ev_archive_get_entry_pathname (comics_document->archive);
+               /* Ignore https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats */
+               if (is_apple_double (name)) {
+                       g_debug ("Not adding AppleDouble file '%s' to the list of files in the comics", name);
+                       continue;
+               }
+
                if (!has_supported_extension (name, supported_extensions)) {
                        g_debug ("Not adding unsupported file '%s' to the list of files in the comics", name);
                        continue;


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