From: Tom Lane Date: Sat, 12 Jun 1999 20:41:25 +0000 (+0000) Subject: Fix critical error noticed by Massimo: copy.c used to have a X-Git-Tag: REL6_5~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9e223d53c5ca32ec6924e62b7b795a2fe08ab15;p=postgresql Fix critical error noticed by Massimo: copy.c used to have a special hack to ensure it would close its output file even after failure due to elog(ERROR) partway through the copy. This is now unnecessary because fd.c takes care of cleaning up open files at transaction abort; worse, after fd.c closed the file copy.c would try to do so *again* at the start of the next COPY command. This would result in havoc in most implementations of stdio library. --- diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index c450b20b26..9d3dcfebfc 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.79 1999/05/29 10:25:29 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.80 1999/06/12 20:41:25 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -239,24 +239,12 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, the class. ----------------------------------------------------------------------------*/ - static FILE *fp; /* static for cleanup */ - static bool file_opened = false; /* static for cleanup */ + FILE *fp; Relation rel; extern char *UserName; /* defined in global.c */ const AclMode required_access = from ? ACL_WR : ACL_RD; int result; - /* - * Close previous file opened for COPY but failed with elog(). There - * should be a better way, but would not be modular. Prevents file - * descriptor leak. bjm 1998/08/29 - */ - if (file_opened) - { - FreeFile(fp); - file_opened = false; - } - rel = heap_openr(relname); if (rel == NULL) elog(ERROR, "COPY command failed. Class %s " @@ -299,7 +287,6 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, "effective uid %d, could not open file '%s' for " "reading. Errno = %s (%d).", geteuid(), filename, strerror(errno), errno); - file_opened = true; } CopyFrom(rel, binary, oids, fp, delim); } @@ -332,14 +319,12 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, "effective uid %d, could not open file '%s' for " "writing. Errno = %s (%d).", geteuid(), filename, strerror(errno), errno); - file_opened = true; } CopyTo(rel, binary, oids, fp, delim); } if (!pipe) { FreeFile(fp); - file_opened = false; } else if (!from) {