[m-users.] Reading the entire directory contents (contribution for the posix library)
Richard O'Keefe
raoknz at gmail.com
Mon Oct 14 19:03:49 AEDT 2019
In building my own Smalltalk library, I had to decide whether to
imitate ftw, glob, readdir, or scandir
(without the sorting). I decided on scandir (report all the names at
once) for a simple reason.
readdir iterates over an external collection which can be modified at
any time by another thread or
process, and as far as I know there are no guarantees about what
happens then. A sca Indir
interface offered the shortest window of vulnerability. I could
program filtering and sorting on the
result afterwards.
I was not thinking about directories with millions of entries at the
time. Now that this has been
brought to my attention, I don't see any way to reconcile these
conflicting forces, but I really DON'T
like to depend on unspecified behaviour. I would throw in a patch to
write-protect a directory while
scanning it, but that won't work with other users' directories and it
won't stop other processes
resetting the permissions.
In short, I think we have a bigger issue than what Mercury does or should do.
On Mon, 14 Oct 2019 at 19:50, Volker Wysk <post at volker-wysk.de> wrote:
>
> Am Montag, den 14.10.2019, 13:57 +1100 schrieb Julien Fischer:
> >
> > On Mon, 14 Oct 2019, Zoltan Somogyi wrote:
> >
> > > On Mon, 14 Oct 2019 13:37:51 +1100 (AEDT), Julien Fischer <
> > > jfischer at opturion.com> wrote:
> > > > > Maybe dir_contents should be added to the "dir" library?
> > > >
> > > > I'm not convinced that it is generally useful enough to warrant
> > > > inclusion it the standard library.
> > >
> > > I think it is useful enough.
> >
> > I disagree, returning the directory contents in a particular order
> > seems quite application specific. Why just return their names?
> > In many circumstances you would presuambly be interested in what
> > kind of file each entry is as well.
> >
> > OTOH, if others feel strongly that this is something that should
> > be in the stdlib, then I suggest the following:
> >
> > % contents(DirName, Result, !IO):
> > % Return the entries of the directory DirName sorted according
> > % to the standard order for strings.
> > %
> > :- pred contents(string::in,
> > io.maybe_partial_result(list(string))::out, io::di, io::uo)
> > is det.
> >
> > % contents(CmpPred, DirName, Result, !IO):
> > % Return the entries of the directoryDirName sorted according
> > % to CmpPred.
> > %
> > :- pred contents(comparison_pred(string)::in(comparison_pred)
> > string::in, io.maybe_partial_result(list(string))::out,
> > io::di, io::uo) is det.
>
> This still introduces complexity (less, but still), which won't be
> needed most of the time.
>
> I suggest adding a front end to your contents() predicates, which is
> just:
>
> :- pred contents(string::in, list(string)::out, io::di, io::uo).
>
> Cheers,
> Volker
>
>
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users
More information about the users
mailing list