Please add {open,close,read}-directory-stream

Bug #315804 reported by Andreas Rottmann
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
Medium
Abdulaziz Ghuloum

Bug Description

While Ikarus provides `directory-list', it doesn't expose the more primitive {open,read,close}dir() API directly. As a consequence, there will be problems with large directories, where unnecessary allocation is forced upon the user even if she would just filter a few items out of the directory, or just do something to all the files in the directory (imagine implementing "rm -rf" in Scheme).

Below I've pasted the description of a possible API, taken from "The Nearly Complete Scheme48 1.3 Reference Manual" [0]:

— procedure: open-directory-stream filename –> dir-stream
— procedure: directory-stream? object –> boolean
— procedure: read-directory-stream dir-stream –> filename or #f
— procedure: close-directory-stream dir-stream –> unspecified

    Directory streams are the low-level interface provided by POSIX to enumerate the contents of a directory. Open-directory-stream opens a new directory stream that will enumerate all of the files within the directory named by filename. Directory-stream? is the disjoint type predicate for directory streams. Read-directory-stream consumes the next filename from dir-stream and returns it, or returns #f if the stream has finished. Note that read-directory-stream will return only simple filenames, not full pathnames. Close-directory-stream closes dir-stream, removing any storage it required in the operating system. Closing an already closed directory stream has no effect.

[0] http://mumble.net/~campbell/darcs/s48-refman/

Related branches

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Will add soon.

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Medium
status: New → Confirmed
Changed in ikarus:
status: Confirmed → In Progress
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Added in revision 1763.

BTW, this should ideally have been provided in an external library, but I couldn't do that at the moment for the lack of tools for parsing the C header files to figure out field types and offsets. Any ideas?

Aziz,,,

Changed in ikarus:
status: In Progress → Fix Committed
Revision history for this message
Derick Eddington (derick-eddington) wrote :

JTMI, if you plan to keep this, ikrt_directory_list could be removed and directory-list could be implemented in terms of this new directory stream functionality. I tried to make a patch to do that, but I ran into a problem I don't understand of getting "unbound identifier" errors when building, caused by using {open,read,close}-directory-stream from scheme/ikarus.posix.ss.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 315804] Re: Please add {open,close,read}-directory-stream

On Apr 9, 2009, at 7:30 PM, Derick Eddington wrote:

> I tried to make a patch to do that, but I ran
> into a problem I don't understand of getting "unbound identifier"
> errors
> when building, caused by using {open,read,close}-directory-stream from
> scheme/ikarus.posix.ss.

The included boot file is pretty old; it does not know about
these new definitions (try running ikarus -b ikarus.4.boot and
see that it doesn't know about directory-streams). So, when
you try to import/use these identifiers in ikarus.posix, it
complains that they're unbound (which is true).

So, before you do this, you (or rather, I) need to refresh the
included boot files (both the 32- and 64-bit versions) to include
directory-streams. Once that's done, they can be used in defining
other primitives.

Alternatively, you can simply define directory-list in ikarus.io.ss
where it can lexically see the definitions of directory-streams and
there will be no problems with that.

Alternatively, you can define it in a new library, and let it
import directory-streams directly from the (ikarus.io) library.
This new library should be included in the list of libraries after
(ikarus.io) otherwise, something wrong might happen (or not).

It's your typical bootstrapping issue.

Aziz,,,

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.