Re: pg_read_file() with virtual files returns empty string - Mailing list pgsql-hackers

From Tom Lane
Subject Re: pg_read_file() with virtual files returns empty string
Date
Msg-id 284570.1593381616@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_read_file() with virtual files returns empty string  (Joe Conway <mail@joeconway.com>)
Responses Re: pg_read_file() with virtual files returns empty string
List pgsql-hackers
Joe Conway <mail@joeconway.com> writes:
> All good stuff -- I believe the attached checks all the boxes.

Looks okay to me, except I think you want

!     if (bytes_to_read > 0)

to be

!     if (bytes_to_read >= 0)

As it stands, a zero request will be treated like -1 (read all the
rest of the file) while ISTM it ought to be an expensive way to
read zero bytes --- perhaps useful to check the filename and seek
offset validity?

> The intention here seems to be that if you pass bytes_to_read = -1 with a
> negative offset, it will give you the last offset bytes of the file.

I think it's just trying to convert bytes_to_read = -1 into an explicit
positive length-to-read in all cases.  We don't need that anymore with
this code, so dropping it is fine.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Revert workarounds for unportability of printf %.*s format?
Next
From: Andy Fan
Date:
Subject: Re: Commitfest 2020-07