Subject: psql -f doesn't complain about directories
From: tgl@sss.pgh.pa.us (Tom Lane)
Date: 11/15/2007 10:44:57 AM
Peter Eisentraut <peter_e@gmx.net> writes:
> Am Mittwoch, 14. November 2007 schrieb Martijn van Oosterhout:
>> It's not the fopen that fails, it's the fgets that returns NULL. We
>> don't subsequently check if that's due to an I/O error or EISDIR or if
>> it's an end-of-file.
> Here is a patch for this.
This seems too far removed from the scene of the crime --- I don't have
a lot of confidence that errno will still be unchanged back in the main
loop. I'd rather see the psql_error printout occur immediately after
the failed fgets call. Either that or you need to be a bit more
proactive about ensuring errno is returned undamaged.
Also, I think you overlooked the case where we get a read error after
having already loaded some data into gets_fromFile's result buffer.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
Subject: psql -f doesn't complain about directories
From: tgl@sss.pgh.pa.us (Tom Lane)
Date: 11/15/2007 12:03:14 PM
Peter Eisentraut <peter_e@gmx.net> writes:
> Am Donnerstag, 15. November 2007 schrieb Tom Lane:
>> This seems too far removed from the scene of the crime
> Yeah, my zeroth attempt was to place this in gets_fromFile(), but there you
> don't have any opportunity to report failure to the main loop. We'd need to
> change the function signature to be able to pass that around. Maybe that's
> better overall.
Well, you could still handle that the same as in your patch: on NULL
return, check ferror. It's just that I don't trust errno to stay
unchanged for very long.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
Subject: psql -f doesn't complain about directories
From: tgl@sss.pgh.pa.us (Tom Lane)
Date: 11/27/2007 3:06:01 PM
Peter Eisentraut <peter_e@gmx.net> writes:
> This should do better:
Looks good to me, though I'd suggest updating gets_fromFile's header comment:
- * The result is a malloc'd string.
+ * The result is a malloc'd string, or NULL on EOF or input error.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at
http://www.postgresql.org/about/donate
|