Skip to content

Crash with "getDirectoryContents:openDirStream: permission denied (Permission denied)" #1062

@wrengr

Description

@wrengr

The Hakyll.Core.Util.File.getRecursiveContents function does not check for permissions before it calls System.Directory.getDirectoryContents. Therefore, when encountering directories that it does not have permissions for, it will crash the program with the aforementioned error message.

In particular, this happens when Hakyll.Core.Runtime.run calls Hakyll.Core.Provider.Internal.newProvider which in turn calls getRecursiveContents. Which is to say, every time we start up our hakyll program it will try to read every single thing underneath the current directory — including things like cabal's dist-newstyle directory, darcs's _darcs directory, and hakyll's own _cache and _site directories! This is horribly inefficient, not to mention a security/correctness problem. Those specific directories have strange names, so it's easy enough to filter them out by setting the shouldIgnoreFile field of the Configuration. However, because shouldIgnoreFile can only look at the basename of each file, it cannot filter out all sorts of other directories the user might want to keep hakyll out of (e.g., I like to have top-level directories with names like 'TODO' or 'BUGS', so I can keep track of notes-to-self; but then maybe I also want my website to have directories with those names). Therefore, it would also be nice to have some mechanism for filtering out directories based on the complete path (relative to top); or even better would be to make it a whitelist instead of a blacklist/filter.


I discovered this crash when trying to work around the crash reported in #1061. I was hoping to triage that crash by simply removing permissions to the directory where the broken symlinks live, which uncovered the current crash.

These two bugs might be more related that it appears on the surface. That is, if System.Directory.doesDirectoryExist returning false is ever interpreted to mean the thing is a (standard) file, then that's a problem: because it returns false for broken symlinks. I'm not sure if that mistake is actually made anywhere in the codebase, but the two crashes make me wonder how posixly-correct the rest of the file manipulation code is.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions