[poppler] 2 commits - glib/poppler-document.cc poppler/PDFDoc.cc poppler/PDFDoc.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Mon Mar 2 00:57:05 PST 2009


 glib/poppler-document.cc |   37 +++++++++++++++++++++++++++++++++----
 poppler/PDFDoc.cc        |   22 +++++++++++-----------
 poppler/PDFDoc.h         |    8 ++++----
 3 files changed, 48 insertions(+), 19 deletions(-)

New commits:
commit dac0542eb793603090416f1b7712ca08253f1e7f
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Mon Mar 2 09:54:22 2009 +0100

    [glib] Correctly handle doc->saveAs() error code.
    
    Fixes bug #19915.

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 6402e69..387f7d1 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -219,6 +219,33 @@ poppler_document_new_from_data (char        *data,
   return _poppler_document_new_from_pdfdoc (newDoc, error);
 }
 
+static gboolean
+handle_save_error (int      err_code,
+		   GError **error)
+{
+  switch (err_code)
+    {
+    case errNone:
+      break;
+    case errOpenFile:
+      g_set_error (error, POPPLER_ERROR,
+		   POPPLER_ERROR_OPEN_FILE,
+		   "Failed to open file for writing");
+      break;
+    case errEncrypted:
+      g_set_error (error, POPPLER_ERROR,
+		   POPPLER_ERROR_ENCRYPTED,
+		   "Document is encrypted");
+      break;
+    default:
+      g_set_error (error, POPPLER_ERROR,
+		   POPPLER_ERROR_INVALID,
+		   "Failed to save document");
+    }
+
+  return err_code == errNone;
+}
+
 /**
  * poppler_document_save:
  * @document: a #PopplerDocument
@@ -245,10 +272,11 @@ poppler_document_save (PopplerDocument  *document,
   filename = g_filename_from_uri (uri, NULL, error);
   if (filename != NULL) {
     GooString *fname = new GooString (filename);
+    int err_code;
     g_free (filename);
 
-    retval = document->doc->saveAs (fname);
-
+    err_code = document->doc->saveAs (fname);
+    retval = handle_save_error (err_code, error);
     delete fname;
   }
 
@@ -282,10 +310,11 @@ poppler_document_save_a_copy (PopplerDocument  *document,
   filename = g_filename_from_uri (uri, NULL, error);
   if (filename != NULL) {
     GooString *fname = new GooString (filename);
+    int err_code;
     g_free (filename);
 
-    retval = document->doc->saveWithoutChangesAs (fname);
-
+    err_code = document->doc->saveWithoutChangesAs (fname);
+    retval = handle_save_error (err_code, error);
     delete fname;
   }
 
commit bfc6572614727565d883b9545d4b6665f3c2fdfe
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sat Feb 28 13:16:49 2009 +0100

    Return an error code instead of a GBool when saving

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index f73359c..1be1261 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -462,14 +462,14 @@ GBool PDFDoc::isLinearized() {
   return lin;
 }
 
-GBool PDFDoc::saveAs(GooString *name, PDFWriteMode mode) {
+int PDFDoc::saveAs(GooString *name, PDFWriteMode mode) {
   FILE *f;
   OutStream *outStr;
-  GBool res;
+  int res;
 
   if (!(f = fopen(name->getCString(), "wb"))) {
     error(-1, "Couldn't open file '%s'", name->getCString());
-    return gFalse;
+    return errOpenFile;
   }
   outStr = new FileOutStream(f,0);
   res = saveAs(outStr, mode);
@@ -478,7 +478,7 @@ GBool PDFDoc::saveAs(GooString *name, PDFWriteMode mode) {
   return res;
 }
 
-GBool PDFDoc::saveAs(OutStream *outStr, PDFWriteMode mode) {
+int PDFDoc::saveAs(OutStream *outStr, PDFWriteMode mode) {
 
   // we don't support files with Encrypt at the moment
   Object obj;
@@ -486,7 +486,7 @@ GBool PDFDoc::saveAs(OutStream *outStr, PDFWriteMode mode) {
   if (!obj.isNull())
   {
     obj.free();
-    return gFalse;
+    return errEncrypted;
   }
   obj.free();
 
@@ -511,17 +511,17 @@ GBool PDFDoc::saveAs(OutStream *outStr, PDFWriteMode mode) {
     }
   }
 
-  return gTrue;
+  return errNone;
 }
 
-GBool PDFDoc::saveWithoutChangesAs(GooString *name) {
+int PDFDoc::saveWithoutChangesAs(GooString *name) {
   FILE *f;
   OutStream *outStr;
-  GBool res;
+  int res;
 
   if (!(f = fopen(name->getCString(), "wb"))) {
     error(-1, "Couldn't open file '%s'", name->getCString());
-    return gFalse;
+    return errOpenFile;
   }
   
   outStr = new FileOutStream(f,0);
@@ -533,7 +533,7 @@ GBool PDFDoc::saveWithoutChangesAs(GooString *name) {
   return res;
 }
 
-GBool PDFDoc::saveWithoutChangesAs(OutStream *outStr) {
+int PDFDoc::saveWithoutChangesAs(OutStream *outStr) {
   int c;
   
   str->reset();
@@ -542,7 +542,7 @@ GBool PDFDoc::saveWithoutChangesAs(OutStream *outStr) {
   }
   str->close();
 
-  return gTrue;
+  return errNone;
 }
 
 void PDFDoc::saveIncrementalUpdate (OutStream* outStr)
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 35b966e..5bc1953 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -197,13 +197,13 @@ public:
   double getPDFVersion() { return pdfVersion; }
 
   // Save this file with another name.
-  GBool saveAs(GooString *name, PDFWriteMode mode=writeStandard);
+  int saveAs(GooString *name, PDFWriteMode mode=writeStandard);
   // Save this file in the given output stream.
-  GBool saveAs(OutStream *outStr, PDFWriteMode mode=writeStandard);
+  int saveAs(OutStream *outStr, PDFWriteMode mode=writeStandard);
   // Save this file with another name without saving changes
-  GBool saveWithoutChangesAs(GooString *name);
+  int saveWithoutChangesAs(GooString *name);
   // Save this file in the given output stream without saving changes
-  GBool saveWithoutChangesAs(OutStream *outStr);
+  int saveWithoutChangesAs(OutStream *outStr);
 
   // Return a pointer to the GUI (XPDFCore or WinPDFCore object).
   void *getGUIData() { return guiData; }


More information about the poppler mailing list