8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.57 2006/06/14 01:28:55 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.58 2006/06/14 17:49:25 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
32
32
33
33
#include <fcntl.h>
34
34
#include <sys/stat.h>
35
- #include <errno.h>
36
35
37
36
#include "libpq-fe.h"
38
37
#include "libpq-int.h"
@@ -458,19 +457,15 @@ lo_import(PGconn *conn, const char *filename)
458
457
lobjOid = lo_creat (conn , INV_READ | INV_WRITE );
459
458
if (lobjOid == InvalidOid )
460
459
{
461
- printfPQExpBuffer (& conn -> errorMessage ,
462
- libpq_gettext ("could not create large object for file \"%s\"\n" ),
463
- filename );
460
+ /* we assume lo_creat() already set a suitable error message */
464
461
(void ) close (fd );
465
462
return InvalidOid ;
466
463
}
467
464
468
465
lobj = lo_open (conn , lobjOid , INV_WRITE );
469
466
if (lobj == -1 )
470
467
{
471
- printfPQExpBuffer (& conn -> errorMessage ,
472
- libpq_gettext ("could not open large object %u\n" ),
473
- lobjOid );
468
+ /* we assume lo_open() already set a suitable error message */
474
469
(void ) close (fd );
475
470
return InvalidOid ;
476
471
}
@@ -484,16 +479,11 @@ lo_import(PGconn *conn, const char *filename)
484
479
if (tmp != nbytes )
485
480
{
486
481
/*
487
- * If the lo_write failed, we are probably in an aborted
488
- * transaction and so lo_close will fail. Try it anyway for
489
- * cleanliness, but don't let it determine the returned error
490
- * message .
482
+ * If lo_write() failed, we are now in an aborted transaction
483
+ * so there's no need for lo_close(); furthermore, if we tried
484
+ * it we'd overwrite the useful error result with a useless one.
485
+ * So just nail the doors shut and get out of town .
491
486
*/
492
- (void ) lo_close (conn , lobj );
493
-
494
- printfPQExpBuffer (& conn -> errorMessage ,
495
- libpq_gettext ("error while writing large object %u\n" ),
496
- lobjOid );
497
487
(void ) close (fd );
498
488
return InvalidOid ;
499
489
}
@@ -511,9 +501,7 @@ lo_import(PGconn *conn, const char *filename)
511
501
512
502
if (lo_close (conn , lobj ) != 0 )
513
503
{
514
- printfPQExpBuffer (& conn -> errorMessage ,
515
- libpq_gettext ("error while writing large object %u\n" ),
516
- lobjOid );
504
+ /* we assume lo_close() already set a suitable error message */
517
505
return InvalidOid ;
518
506
}
519
507
@@ -542,8 +530,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
542
530
lobj = lo_open (conn , lobjId , INV_READ );
543
531
if (lobj == -1 )
544
532
{
545
- printfPQExpBuffer (& conn -> errorMessage ,
546
- libpq_gettext ("could not open large object %u\n" ), lobjId );
533
+ /* we assume lo_open() already set a suitable error message */
547
534
return -1 ;
548
535
}
549
536
@@ -569,26 +556,31 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
569
556
if (tmp != nbytes )
570
557
{
571
558
printfPQExpBuffer (& conn -> errorMessage ,
572
- libpq_gettext ("error while writing to file \"%s\": %s\n" ),
559
+ libpq_gettext ("could not write to file \"%s\": %s\n" ),
573
560
filename , pqStrerror (errno , sebuf , sizeof (sebuf )));
574
561
(void ) lo_close (conn , lobj );
575
562
(void ) close (fd );
576
563
return -1 ;
577
564
}
578
565
}
579
566
580
- if (lo_close (conn , lobj ) != 0 || nbytes < 0 )
567
+ /*
568
+ * If lo_read() failed, we are now in an aborted transaction
569
+ * so there's no need for lo_close(); furthermore, if we tried
570
+ * it we'd overwrite the useful error result with a useless one.
571
+ * So skip lo_close() if we got a failure result.
572
+ */
573
+ if (nbytes < 0 ||
574
+ lo_close (conn , lobj ) != 0 )
581
575
{
582
- printfPQExpBuffer (& conn -> errorMessage ,
583
- libpq_gettext ("error while reading large object %u\n" ),
584
- lobjId );
576
+ /* assume lo_read() or lo_close() left a suitable error message */
585
577
result = -1 ;
586
578
}
587
579
588
580
if (close (fd ))
589
581
{
590
582
printfPQExpBuffer (& conn -> errorMessage ,
591
- libpq_gettext ("error while writing to file \"%s\": %s\n" ),
583
+ libpq_gettext ("could not write to file \"%s\": %s\n" ),
592
584
filename , pqStrerror (errno , sebuf , sizeof (sebuf )));
593
585
result = -1 ;
594
586
}
0 commit comments