Directory not accessible

41 views
Skip to first unread message

Russ Abbott

unread,
Jul 6, 2015, 5:50:36 PM7/6/15
to racket...@googlegroups.com
I installed Racket in a directory for which I have access. Yet when I attempted to run the example code on the Racket Home page:

(for ([path (in-directory)]
#:when (regexp-match? #rx"[.]rkt$" path))
(printf "source file: ~a\n" path))

I got this error message.

Racket\collects\racket\private\for.rkt:1973:2: directory-list: could not open directory
path: C:\Users\facuser\AppData\Local\Application Data
system error: Access is denied.; errno=5

I have access to everything on the path except Application Data.

How can I get this to run?

If special permissions are needed, why is this example shown so prominently?

Thanks.

David T. Pierson

unread,
Jul 6, 2015, 11:27:11 PM7/6/15
to racket...@googlegroups.com, Russ Abbott
On Mon, Jul 06, 2015 at 02:50:36PM -0700, Russ Abbott wrote:
> I installed Racket in a directory for which I have access. Yet when I attempted to run the example code on the Racket Home page:
>
> (for ([path (in-directory)]
> #:when (regexp-match? #rx"[.]rkt$" path))
> (printf "source file: ~a\n" path))
>
> I got this error message.
>
> Racket\collects\racket\private\for.rkt:1973:2: directory-list: could not open directory
> path: C:\Users\facuser\AppData\Local\Application Data
> system error: Access is denied.; errno=5

As coded with no arguments, (in-directory) produces a sequence that will
traverse all files and subdirectories (of the current directory)
recursively [1].

On Windows that runs into permissions problems even in one's own home
directory.

The second argument to in-directory can control the recursion, but to
avoid recursion entirely use directory-list [2] instead:

(for ([path (directory-list)]
#:when (regexp-match? #rx"[.]rkt$" path))
(printf "source file: ~a\n" path))

As a side note, I tried using file-or-directory-permissions [3] to avoid
recursing into directories with no read or execute permission, but it
turns out some directories are inaccessible on Windows even though
file-or-directory-permissions returns '(execute write read). I don't
know enough about Windows permissions to know whether that is expected.

[1] http://docs.racket-lang.org/reference/sequences.html#(def._((lib._racket/private/base..rkt)._in-directory))

[2] http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._directory-list%29%29

[3] http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28quote._~23~25kernel%29._file-or-directory-permissions%29%29

David

Neil Van Dyke

unread,
Jul 6, 2015, 11:53:41 PM7/6/15
to racket...@googlegroups.com
David T. Pierson wrote on 07/06/2015 11:27 PM:
> As a side note, I tried using file-or-directory-permissions [3] to avoid
> recursing into directories with no read or execute permission, but it

BTW, before anyone does a lot more work on filesystem access control
semantics... I think the usual case with filesystems is that there's no
point to asking whether you have permission to do an operation, as
opposed to just attempting the operation you want to do. Even if you
check what you think is the pertinent access control info before
attempting operation, and your interpretation of the info is correct,
the info might change on you in the interim, before you attempt the
operation. In the case of the info changing on you, and consequently the
operation failing when you thought it would succeed, normally you would
handle that case in the same way that you'd handle the case of the info
you check before attempting saying no.

(There are exceptions, but I think they're unusual. And, even in some
of the exceptions, a more multi-platform robust way to, e.g., check
readability of a directory in advance is to attempt to read the
directory now, not ask about access control info and try to interpret
the info.)

Neil V.

David T. Pierson

unread,
Jul 7, 2015, 12:51:00 AM7/7/15
to racket...@googlegroups.com
On Mon, Jul 06, 2015 at 11:53:38PM -0400, Neil Van Dyke wrote:
> David T. Pierson wrote on 07/06/2015 11:27 PM:
> >As a side note, I tried using file-or-directory-permissions [3] to avoid
> >recursing into directories with no read or execute permission, but it
>
> BTW, before anyone does a lot more work on filesystem access control
> semantics... I think the usual case with filesystems is that there's no
> point to asking whether you have permission to do an operation, as opposed
> to just attempting the operation you want to do. Even if you check what you

Good point; I agree. But then is in-directory too blunt a tool? Well,
I suppose you could specify a use-dir? function that attempts a
directory-list and returns #f if an exception occurs:

(define (descend? path)
(with-handlers ([void (lambda (exn) #f)])
(directory-list path)))

(for ([path (in-directory #f descend?)]
#:when (regexp-match? #rx"[.]rkt$" path))
(printf "source file: ~a\n" path))

Having to generate the directory listing twice for each subdirectory is
a little unfortunate, but in cases where efficiency is critical a more
discriminatory approach could be used.

But to go back to the OP: is this example too error-prone to have on the
home page?

David

Russ Abbott

unread,
Jul 7, 2015, 12:39:13 PM7/7/15
to David T. Pierson, racket...@googlegroups.com
Thanks David and Neil for your answers.  My question was prompted simply by curiosity. I downloaded and installed Racket having had no previous experience with it. Simply as a way to try something I copied the code from the Home page just to see what would happen. What happened was that I got a confusing error message.  The point, as David suggests, is that code like that shouldn't be on the Home page! That was my original point also.


--
You received this message because you are subscribed to a topic in the Google Groups "Racket Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/racket-users/lJ_5bPhRD2o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages