Commit 441a9cd5 authored by Eric Toombs's avatar Eric Toombs Committed by Albert Astals Cid
Browse files

Improved error reporting of ErrOpenFile errors

See bug #20660 for more information
parent 16af0ced
......@@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <goo/GooList.h>
#include <splash/SplashBitmap.h>
#include <GlobalParams.h>
......@@ -73,12 +75,18 @@ _poppler_document_new_from_pdfdoc (PDFDoc *newDoc,
document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL);
if (!newDoc->isOk()) {
int fopen_errno;
switch (newDoc->getErrorCode())
{
case errOpenFile:
g_set_error (error, POPPLER_ERROR,
POPPLER_ERROR_OPEN_FILE,
"Failed to open the PDF file");
// If there was an error opening the file, count it as a G_FILE_ERROR
// and set the GError parameters accordingly. (this assumes that the
// only way to get an errOpenFile error is if newDoc was created using
// a filename and thus fopen was called, which right now is true.
fopen_errno = newDoc->getFopenErrno();
g_set_error (error, G_FILE_ERROR,
g_file_error_from_errno (fopen_errno),
strerror(fopen_errno));
break;
case errBadCatalog:
g_set_error (error, POPPLER_ERROR,
......
......@@ -18,6 +18,7 @@
// Copyright (C) 2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2008 Pino Toscano <pino@kde.org>
// Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Eric Toombs <ewtoombs@uwaterloo.ca>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -32,6 +33,7 @@
#include <locale.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
......@@ -71,7 +73,6 @@
PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
GooString *userPassword, void *guiDataA) {
Object obj;
GooString *fileName1, *fileName2;
ok = gFalse;
errCode = errNone;
......@@ -87,33 +88,42 @@ PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
#endif
fileName = fileNameA;
fileName1 = fileName;
// try to open file
fileName2 = NULL;
GooString *fn = fileName->copy(); //a modifiable copy of fileName
for (int trial = 1; trial <= 3; trial++) {
#ifdef VMS
if (!(file = fopen(fileName1->getCString(), "rb", "ctx=stm"))) {
error(-1, "Couldn't open file '%s'", fileName1->getCString());
errCode = errOpenFile;
return;
}
file = fopen(fn->getCString(), "rb", "ctx=stm");
#else
if (!(file = fopen(fileName1->getCString(), "rb"))) {
fileName2 = fileName->copy();
fileName2->lowerCase();
if (!(file = fopen(fileName2->getCString(), "rb"))) {
fileName2->upperCase();
if (!(file = fopen(fileName2->getCString(), "rb"))) {
error(-1, "Couldn't open file '%s'", fileName->getCString());
delete fileName2;
errCode = errOpenFile;
return;
}
file = fopen(fn->getCString(), "rb");
#endif
if (file != NULL)
// fopen() has succeeded!
break;
// fopen() has failed.
if (errno != ENOENT || trial == 3) {
/*
* Either an error has occurred other than "No such file or
* directory", or we are on trial 3 and we are out of alternative file
* names.
*/
error(-1, "Couldn't open file '%s': %s.", fileName->getCString(),
strerror(errno));
errCode = errOpenFile;
// Keep a copy of the errno returned by fopen so that it can be
// referred to later.
fopenErrno = errno;
return;
}
delete fileName2;
// fn wasn't found.
if (trial == 1)
fn->lowerCase();
else //if (trial == 2) implicit; 3 and 1 have already been checked for.
fn->upperCase();
}
#endif
delete fn;
// create stream
obj.initNull();
......
......@@ -18,6 +18,7 @@
// Copyright (C) 2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2008 Pino Toscano <pino@kde.org>
// Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Eric Toombs <ewtoombs@uwaterloo.ca>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -77,6 +78,10 @@ public:
// Get the error code (if isOk() returns false).
int getErrorCode() { return errCode; }
// Get the error code returned by fopen() (if getErrorCode() ==
// errOpenFile).
int getFopenErrno() { return fopenErrno; }
// Get file name.
GooString *getFileName() { return fileName; }
......@@ -238,6 +243,9 @@ private:
GBool ok;
int errCode;
//If there is an error opening the PDF file with fopen() in the constructor,
//then the POSIX errno will be here.
int fopenErrno;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment