7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.145 2002/02/12 21:25:41 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.146 2002/02/23 21:46:02 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -326,12 +326,20 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
326
326
}
327
327
else
328
328
{
329
+ struct stat st ;
329
330
fp = AllocateFile (filename , PG_BINARY_R );
330
- if (fp == NULL )
331
+
332
+ if (fp == NULL )
331
333
elog (ERROR , "COPY command, running in backend with "
332
334
"effective uid %d, could not open file '%s' for "
333
335
"reading. Errno = %s (%d)." ,
334
336
(int ) geteuid (), filename , strerror (errno ), errno );
337
+
338
+ fstat (fileno (fp ),& st );
339
+ if ( S_ISDIR (st .st_mode ) ){
340
+ fclose (fp );
341
+ elog (ERROR ,"COPY: %s is a directory." ,filename );
342
+ }
335
343
}
336
344
CopyFrom (rel , binary , oids , fp , delim , null_print );
337
345
}
@@ -360,6 +368,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
360
368
else
361
369
{
362
370
mode_t oumask ; /* Pre-existing umask value */
371
+ struct stat st ;
363
372
364
373
/*
365
374
* Prevent write to relative path ... too easy to shoot
@@ -378,6 +387,11 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
378
387
"effective uid %d, could not open file '%s' for "
379
388
"writing. Errno = %s (%d)." ,
380
389
(int ) geteuid (), filename , strerror (errno ), errno );
390
+ fstat (fileno (fp ),& st );
391
+ if ( S_ISDIR (st .st_mode ) ){
392
+ fclose (fp );
393
+ elog (ERROR ,"COPY: %s is a directory." ,filename );
394
+ }
381
395
}
382
396
CopyTo (rel , binary , oids , fp , delim , null_print );
383
397
}
0 commit comments