@@ -501,15 +501,19 @@ tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
501501 state -> writepos_file ,
502502 state -> writepos_offset ,
503503 SEEK_SET ) != 0 )
504- elog (ERROR , "tuplestore seek failed" );
504+ ereport (ERROR ,
505+ (errcode_for_file_access (),
506+ errmsg ("could not seek in tuplestore temporary file: %m" )));
505507 }
506508 else
507509 {
508510 if (BufFileSeek (state -> myfile ,
509511 readptr -> file ,
510512 readptr -> offset ,
511513 SEEK_SET ) != 0 )
512- elog (ERROR , "tuplestore seek failed" );
514+ ereport (ERROR ,
515+ (errcode_for_file_access (),
516+ errmsg ("could not seek in tuplestore temporary file: %m" )));
513517 }
514518 break ;
515519 default :
@@ -834,7 +838,9 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
834838 if (BufFileSeek (state -> myfile ,
835839 state -> writepos_file , state -> writepos_offset ,
836840 SEEK_SET ) != 0 )
837- elog (ERROR , "tuplestore seek to EOF failed" );
841+ ereport (ERROR ,
842+ (errcode_for_file_access (),
843+ errmsg ("could not seek in tuplestore temporary file: %m" )));
838844 state -> status = TSS_WRITEFILE ;
839845
840846 /*
@@ -936,7 +942,9 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
936942 if (BufFileSeek (state -> myfile ,
937943 readptr -> file , readptr -> offset ,
938944 SEEK_SET ) != 0 )
939- elog (ERROR , "tuplestore seek failed" );
945+ ereport (ERROR ,
946+ (errcode_for_file_access (),
947+ errmsg ("could not seek in tuplestore temporary file: %m" )));
940948 state -> status = TSS_READFILE ;
941949 /* FALL THRU into READFILE case */
942950
@@ -998,7 +1006,9 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
9981006 if (BufFileSeek (state -> myfile , 0 ,
9991007 - (long ) (tuplen + sizeof (unsigned int )),
10001008 SEEK_CUR ) != 0 )
1001- elog (ERROR , "bogus tuple length in backward scan" );
1009+ ereport (ERROR ,
1010+ (errcode_for_file_access (),
1011+ errmsg ("could not seek in tuplestore temporary file: %m" )));
10021012 Assert (!state -> truncated );
10031013 return NULL ;
10041014 }
@@ -1013,7 +1023,9 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
10131023 if (BufFileSeek (state -> myfile , 0 ,
10141024 - (long ) tuplen ,
10151025 SEEK_CUR ) != 0 )
1016- elog (ERROR , "bogus tuple length in backward scan" );
1026+ ereport (ERROR ,
1027+ (errcode_for_file_access (),
1028+ errmsg ("could not seek in tuplestore temporary file: %m" )));
10171029 tup = READTUP (state , tuplen );
10181030 return tup ;
10191031
@@ -1213,7 +1225,9 @@ tuplestore_rescan(Tuplestorestate *state)
12131225 case TSS_READFILE :
12141226 readptr -> eof_reached = false;
12151227 if (BufFileSeek (state -> myfile , 0 , 0L , SEEK_SET ) != 0 )
1216- elog (ERROR , "tuplestore seek to start failed" );
1228+ ereport (ERROR ,
1229+ (errcode_for_file_access (),
1230+ errmsg ("could not seek in tuplestore temporary file: %m" )));
12171231 break ;
12181232 default :
12191233 elog (ERROR , "invalid tuplestore state" );
@@ -1276,14 +1290,18 @@ tuplestore_copy_read_pointer(Tuplestorestate *state,
12761290 state -> writepos_file ,
12771291 state -> writepos_offset ,
12781292 SEEK_SET ) != 0 )
1279- elog (ERROR , "tuplestore seek failed" );
1293+ ereport (ERROR ,
1294+ (errcode_for_file_access (),
1295+ errmsg ("could not seek in tuplestore temporary file: %m" )));
12801296 }
12811297 else
12821298 {
12831299 if (BufFileSeek (state -> myfile ,
12841300 dptr -> file , dptr -> offset ,
12851301 SEEK_SET ) != 0 )
1286- elog (ERROR , "tuplestore seek failed" );
1302+ ereport (ERROR ,
1303+ (errcode_for_file_access (),
1304+ errmsg ("could not seek in tuplestore temporary file: %m" )));
12871305 }
12881306 }
12891307 else if (srcptr == state -> activeptr )
@@ -1427,10 +1445,10 @@ getlen(Tuplestorestate *state, bool eofOK)
14271445 nbytes = BufFileRead (state -> myfile , (void * ) & len , sizeof (len ));
14281446 if (nbytes == sizeof (len ))
14291447 return len ;
1430- if (nbytes != 0 )
1431- elog (ERROR , "unexpected end of tape" );
1432- if (! eofOK )
1433- elog ( ERROR , "unexpected end of data" );
1448+ if (nbytes != 0 || ! eofOK )
1449+ ereport (ERROR ,
1450+ ( errcode_for_file_access (),
1451+ errmsg ( "could not read from tuplestore temporary file: %m" )) );
14341452 return 0 ;
14351453}
14361454
@@ -1469,14 +1487,20 @@ writetup_heap(Tuplestorestate *state, void *tup)
14691487
14701488 if (BufFileWrite (state -> myfile , (void * ) & tuplen ,
14711489 sizeof (tuplen )) != sizeof (tuplen ))
1472- elog (ERROR , "write failed" );
1490+ ereport (ERROR ,
1491+ (errcode_for_file_access (),
1492+ errmsg ("could not write to tuplestore temporary file: %m" )));
14731493 if (BufFileWrite (state -> myfile , (void * ) tupbody ,
14741494 tupbodylen ) != (size_t ) tupbodylen )
1475- elog (ERROR , "write failed" );
1495+ ereport (ERROR ,
1496+ (errcode_for_file_access (),
1497+ errmsg ("could not write to tuplestore temporary file: %m" )));
14761498 if (state -> backward ) /* need trailing length word? */
14771499 if (BufFileWrite (state -> myfile , (void * ) & tuplen ,
14781500 sizeof (tuplen )) != sizeof (tuplen ))
1479- elog (ERROR , "write failed" );
1501+ ereport (ERROR ,
1502+ (errcode_for_file_access (),
1503+ errmsg ("could not write to tuplestore temporary file: %m" )));
14801504
14811505 FREEMEM (state , GetMemoryChunkSpace (tuple ));
14821506 heap_free_minimal_tuple (tuple );
@@ -1495,10 +1519,14 @@ readtup_heap(Tuplestorestate *state, unsigned int len)
14951519 tuple -> t_len = tuplen ;
14961520 if (BufFileRead (state -> myfile , (void * ) tupbody ,
14971521 tupbodylen ) != (size_t ) tupbodylen )
1498- elog (ERROR , "unexpected end of data" );
1522+ ereport (ERROR ,
1523+ (errcode_for_file_access (),
1524+ errmsg ("could not read from tuplestore temporary file: %m" )));
14991525 if (state -> backward ) /* need trailing length word? */
15001526 if (BufFileRead (state -> myfile , (void * ) & tuplen ,
15011527 sizeof (tuplen )) != sizeof (tuplen ))
1502- elog (ERROR , "unexpected end of data" );
1528+ ereport (ERROR ,
1529+ (errcode_for_file_access (),
1530+ errmsg ("could not read from tuplestore temporary file: %m" )));
15031531 return (void * ) tuple ;
15041532}
0 commit comments