]> granicus.if.org Git - postgresql/commitdiff
Fix critical error noticed by Massimo: copy.c used to have a
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Jun 1999 20:41:25 +0000 (20:41 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Jun 1999 20:41:25 +0000 (20:41 +0000)
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.

src/backend/commands/copy.c

index c450b20b26a6aa1b292b00ed9ab57675cf4ca43c..9d3dcfebfcd56a6b0bc9c550fca2b6026a921c60 100644 (file)
@@ -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)
                {