On Mon, Jan 14, 2019 at 10:35 AM Mateusz Krawczuk mkrawczuk@opera.com wrote:
Wouldn't it be better to go straight to Pike-devel to preserve the wisdom for broader audience?
On the odd chance that pike-devel want late night musings in Swedish, then sure. I'm going to veto anyone else doing that though, so I don't think the chances of everyone agreeing to see my badly thought thru rants are high.
Anyways, time to write something more coherent:
We need a better API for handling directory listing, especially for coupling the listings with their metadata (stat struct). At the moment this is the most compact way of listing files in a dir sorted by creation time I could come up with:
string mydir = "/tmp"; array files = get_dir(mydir); files = combine_path(mydir, files[*]); sort(files, file_stat(files[*])->ctime);
And whenever automap feels like a good idea the API probably needs to be looked at. This will also explode in your face if files have been deleted between get_dir() and file_stat().
The question is what that API should be. We have a slightly extended API available in Filesystem:
object fs = Filesystem.System("/tmp"); array files = fs->get_dir(); sort(files, fs->get_stats()->ctime);
While this is cute if the directory contents is completely static (see Filesystem.Tar), not so much otherwise.
I have some ideas of how a new API should look, basically:
1. Add a function (possibly to Filesystem) that returns both the listing and stats, so that TOCTOU error handling can be kept away from the user. 2. Add a convenience function where you can request a already sorted list based on any criteria you want. 3. bonus: more iterators
Regards,
pike-devel@lists.lysator.liu.se