Re: [PATCH v1] pg_ls_tmpdir to show directories

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, "Bossart, Nathan" <bossartn(at)amazon(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: [PATCH v1] pg_ls_tmpdir to show directories
Date: 2019-12-28 15:02:12
Message-ID: alpine.DEB.2.21.1912281555010.24861@pseudo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello Justin,

>> Ok, so this suggests recursing into subdirs, which requires to make a
>> separate function of the inner loop.
> Yea, it suggests that; but, SRF_RETURN_NEXT doesn't make that very easy.
> It'd need to accept the fcinfo argument, and pg_ls_dir_files would call it once
> for every tuple to be returned. So it's recursive and saves its state...
> The attached is pretty ugly, but I can't see how to do better.

Hmmm… I do agree with pretty ugly:-)

If it really neads to be in the structure, why not save the open directory
field in the caller and restore it after the recursive call, and pass the
rest of the structure as a pointer? Something like:

... root_function(...)
struct status_t status = initialization();
call rec_function(&status, path)

... rec_function(struct *status, path)
status->dir = opendir(path);
for (dir contents)
if (it_is_a_dir)
/* some comment about why we do that… */
dir_t saved = status->dir;
status->dir = NULL;
rec_function(status, subpath);
status->dir = saved;
closedir(status->dir), status->dir = NULL;

> The alternative seems to be to build up a full list of pathnames in the SRF
> initial branch, and stat them all later. Or stat them all in the INITIAL case,
> and keep a list of stat structures to be emited during future calls.


In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2019-12-28 16:03:27 Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions
Previous Message John Naylor 2019-12-28 14:50:24 Re: use CLZ instruction in AllocSetFreeIndex()