Skip to content

way to prevent openDirStream from following symlinks #134

@joeyh

Description

@joeyh

haskell/directory#97 needs a way to list the content of a directory that avoids following a symlink. The unix way to do that is open with O_NOFOLLOW and then passing the fd to fdopendir. This library does not provide a way to do that; could it?


One way would be to add

openDirStreamFromFd :: Fd -> IO DirStream

But that is fairly low-level. The user needs to take care to avoid reusing the Fd after calling it. Also, while some of the OpenFileFlags may make sense for opening a directory, most of them probably don't. And the user would need to take care to set O_CLOEXEC to avoid a possible fd leak.

This interface would avoid those problems (pass O_CLOEXEC always):

data OpenDirFlags = OpenDirFlags { dir_nofollow :: Bool, ... }

openDirStream' :: OpenDirFlags -> IO DirStream

Assuming this is exported from the same module as OpenFileFlags, the fields in OpenDirFlags need to be qualified to avoid name conflicts. Or OpenFileFlags could be used for openDirStream', but a number of those flags don't make sense for opening a directory.

Also openDirStream could be changed to take such an OpenDirFlags, if an API bump appeals.

I'd be happy to implement whichever of these you prefer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions