Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9f90b2

Browse files
committed
Improve error message from failed LOAD command (include
kernel's error description when file is not accessible).
1 parent b21005f commit f9f90b2

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/backend/tcop/utility.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.59 1999/03/17 22:53:19 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.60 1999/05/22 19:49:42 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -612,22 +612,12 @@ ProcessUtility(Node *parsetree,
612612
case T_LoadStmt:
613613
{
614614
LoadStmt *stmt = (LoadStmt *) parsetree;
615-
FILE *fp;
616-
char *filename;
617615

618616
PS_SET_STATUS(commandTag = "LOAD");
619617
CHECK_IF_ABORTED();
620618

621-
filename = stmt->filename;
622-
closeAllVfds();
623-
#ifndef __CYGWIN32__
624-
if ((fp = AllocateFile(filename, "r")) == NULL)
625-
#else
626-
if ((fp = AllocateFile(filename, "rb")) == NULL)
627-
#endif
628-
elog(ERROR, "LOAD: could not open file '%s'", filename);
629-
FreeFile(fp);
630-
load_file(filename);
619+
closeAllVfds(); /* probably not necessary... */
620+
load_file(stmt->filename);
631621
}
632622
break;
633623

src/backend/utils/fmgr/dfmgr.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.24 1999/05/10 00:46:13 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.25 1999/05/22 19:49:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -148,7 +148,7 @@ handle_load(char *filename, char *funcname)
148148
if (file_scanner == (DynamicFileList *) NULL)
149149
{
150150
if (stat(filename, &stat_buf) == -1)
151-
elog(ERROR, "stat failed on file %s", filename);
151+
elog(ERROR, "stat failed on file '%s': %m", filename);
152152

153153
for (file_scanner = file_list;
154154
file_scanner != (DynamicFileList *) NULL
@@ -237,13 +237,17 @@ void
237237
load_file(char *filename)
238238
{
239239
DynamicFileList *file_scanner,
240-
*p;
240+
*p;
241241
struct stat stat_buf;
242-
243242
int done = 0;
244243

244+
/*
245+
* We need to do stat() in order to determine whether this is the
246+
* same file as a previously loaded file; it's also handy so as to
247+
* give a good error message if bogus file name given.
248+
*/
245249
if (stat(filename, &stat_buf) == -1)
246-
elog(ERROR, "stat failed on file %s", filename);
250+
elog(ERROR, "LOAD: could not open file '%s': %m", filename);
247251

248252
if (file_list != (DynamicFileList *) NULL
249253
&& !NOT_EQUAL(stat_buf, *file_list))

0 commit comments

Comments
 (0)