Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2193beb

Browse files
committed
Further thoughts about lo_export/lo_import error handling: if one of
the lower-level large object functions fails, it will have already seta suitable error message --- probably something from the backend ---and it is not useful to overwrite that with a generic 'error whilereading large object' message. So remove redundant messages.
1 parentf3164c0 commit2193beb

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

‎src/interfaces/libpq/fe-lobj.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.57 2006/06/1401:28:55 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.58 2006/06/1417:49:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -32,7 +32,6 @@
3232

3333
#include<fcntl.h>
3434
#include<sys/stat.h>
35-
#include<errno.h>
3635

3736
#include"libpq-fe.h"
3837
#include"libpq-int.h"
@@ -458,19 +457,15 @@ lo_import(PGconn *conn, const char *filename)
458457
lobjOid=lo_creat(conn,INV_READ |INV_WRITE);
459458
if (lobjOid==InvalidOid)
460459
{
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 */
464461
(void)close(fd);
465462
returnInvalidOid;
466463
}
467464

468465
lobj=lo_open(conn,lobjOid,INV_WRITE);
469466
if (lobj==-1)
470467
{
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 */
474469
(void)close(fd);
475470
returnInvalidOid;
476471
}
@@ -484,16 +479,11 @@ lo_import(PGconn *conn, const char *filename)
484479
if (tmp!=nbytes)
485480
{
486481
/*
487-
* Ifthelo_write failed, we areprobably in an aborted
488-
*transaction andsolo_close will fail. Try it anyway for
489-
*cleanliness, but don't let it determinethereturned error
490-
*message.
482+
* If lo_write() failed, we arenow in an aborted transaction
483+
* sothere's no need for lo_close(); furthermore, if we tried
484+
*it we'd overwritetheuseful error result with a useless one.
485+
*So just nail the doors shut and get out of town.
491486
*/
492-
(void)lo_close(conn,lobj);
493-
494-
printfPQExpBuffer(&conn->errorMessage,
495-
libpq_gettext("error while writing large object %u\n"),
496-
lobjOid);
497487
(void)close(fd);
498488
returnInvalidOid;
499489
}
@@ -511,9 +501,7 @@ lo_import(PGconn *conn, const char *filename)
511501

512502
if (lo_close(conn,lobj)!=0)
513503
{
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 */
517505
returnInvalidOid;
518506
}
519507

@@ -542,8 +530,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
542530
lobj=lo_open(conn,lobjId,INV_READ);
543531
if (lobj==-1)
544532
{
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 */
547534
return-1;
548535
}
549536

@@ -569,26 +556,31 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
569556
if (tmp!=nbytes)
570557
{
571558
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"),
573560
filename,pqStrerror(errno,sebuf,sizeof(sebuf)));
574561
(void)lo_close(conn,lobj);
575562
(void)close(fd);
576563
return-1;
577564
}
578565
}
579566

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)
581575
{
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 */
585577
result=-1;
586578
}
587579

588580
if (close(fd))
589581
{
590582
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"),
592584
filename,pqStrerror(errno,sebuf,sizeof(sebuf)));
593585
result=-1;
594586
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp