[2002-01-16 17:47] Douglas Trainor said: | I'd like to report a bug in 7.1.3 psql (at least on a 64-bit Alpha Linux box). | Maybe someone can confirm this or maybe it's fixed in 7.2
The attached patch is for 7.2, but might apply (with some fuzz) to 7.1.x. files: src/backend/commands/copy.c src/bin/psql/copy.c note: Add fstat / S_ISDIR checks to make sure we're not trying to use a directory for COPY TO/FROM. cheers. brent -- "Develop your talent, man, and leave the world something. Records are really gifts from people. To think that an artist would love you enough to share his music with anyone is a beautiful thing." -- Duane Allman
Index: src/backend/commands/copy.c =================================================================== RCS file: /var/cvsup/pgsql/src/backend/commands/copy.c,v retrieving revision 1.144 diff -c -r1.144 copy.c *** src/backend/commands/copy.c 4 Dec 2001 21:19:57 -0000 1.144 --- src/backend/commands/copy.c 17 Jan 2002 11:56:27 -0000 *************** *** 326,337 **** } else { fp = AllocateFile(filename, PG_BINARY_R); ! if (fp == NULL) elog(ERROR, "COPY command, running in backend with " "effective uid %d, could not open file '%s' for " "reading. Errno = %s (%d).", (int) geteuid(), filename, strerror(errno), errno); } CopyFrom(rel, binary, oids, fp, delim, null_print); } --- 326,343 ---- } else { + struct stat st; fp = AllocateFile(filename, PG_BINARY_R); ! ! if (fp == NULL) elog(ERROR, "COPY command, running in backend with " "effective uid %d, could not open file '%s' for " "reading. Errno = %s (%d).", (int) geteuid(), filename, strerror(errno), errno); + + fstat(fileno(fp),&st); + if( S_ISDIR(st.st_mode) ) + elog(ERROR,"COPY: %s is a directory.",filename); } CopyFrom(rel, binary, oids, fp, delim, null_print); } Index: src/bin/psql/copy.c =================================================================== RCS file: /var/cvsup/pgsql/src/bin/psql/copy.c,v retrieving revision 1.19 diff -c -r1.19 copy.c *** src/bin/psql/copy.c 2 Jun 2001 18:25:18 -0000 1.19 --- src/bin/psql/copy.c 17 Jan 2002 11:58:11 -0000 *************** *** 11,16 **** --- 11,17 ---- #include <errno.h> #include <assert.h> #include <signal.h> + #include <sys/stat.h> #ifndef WIN32 #include <unistd.h> /* for isatty */ #else *************** *** 233,238 **** --- 234,240 ---- struct copy_options *options; PGresult *result; bool success; + struct stat st; /* parse options */ options = parse_slash_copy(args); *************** *** 292,298 **** free_copy_options(options); return false; } ! result = PSQLexec(query); switch (PQresultStatus(result)) --- 294,308 ---- free_copy_options(options); return false; } ! /* make sure the specified file is not a directory */ ! fstat(fileno(copystream),&st); ! if( S_ISDIR(st.st_mode) ){ ! psql_error("%s: cannot COPY TO/FROM a directory\n", ! options->file); ! free_copy_options(options); ! return false; ! } ! result = PSQLexec(query); switch (PQresultStatus(result))
---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html