<commit_before>{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}

module Pipes.Files.Directory where

import           Control.Applicative
import           Control.Exception (IOException)
import qualified Control.Exception as E
import           Control.Monad
import qualified Data.ByteString as B
import           Data.Maybe (fromMaybe)
import           Foreign
import           Foreign.C
import           Pipes
import           Pipes.Files.Types
import           Pipes.Safe
import           Prelude hiding (FilePath)
import           System.Posix.ByteString.FilePath
import           System.Posix.Files.ByteString

type CDir = ()
type CDirent = ()
type DirStream = Ptr CDir

-- | @openDirStream dir@ calls @opendir@ to obtain a directory stream for
--   @dir@.
openDirStream :: RawFilePath -> IO DirStream
openDirStream name = withFilePath name $ \s ->
    throwErrnoPathIfNullRetry "openDirStream" name $ c_opendir s
{-# INLINE openDirStream #-}

foreign import ccall unsafe "__hsunix_opendir"
   c_opendir :: CString  -> IO (Ptr CDir)

getDirectoryContentsAndAttrs :: RawFilePath -> IO [(RawFilePath, CUInt)]
getDirectoryContentsAndAttrs path = do
    resetErrno<commit_msg>Fix for a missing function name<commit_after>{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}

module Pipes.Files.Directory where

import           Control.Applicative
import           Control.Exception (IOException)
import qualified Control.Exception as E
import           Control.Monad
import qualified Data.ByteString as B
import           Data.Maybe (fromMaybe)
import           Foreign
import           Foreign.C
import           Pipes
import           Pipes.Files.Types
import           Pipes.Safe
import           Prelude hiding (FilePath)
import           System.Posix.ByteString.FilePath
import           System.Posix.Files.ByteString

type CDir = ()
type CDirent = ()
type DirStream = Ptr CDir

-- | @openDirStream dir@ calls @opendir@ to obtain a directory stream for
--   @dir@.
openDirStream :: RawFilePath -> IO DirStream
openDirStream name = withFilePath name $ \s ->
    throwErrnoPathIfNullRetry "openDirStream" name $ c_opendir s
{-# INLINE openDirStream #-}

foreign import ccall unsafe "opendir"
   c_opendir :: CString  -> IO (Ptr CDir)

getDirectoryContentsAndAttrs :: RawFilePath -> IO [(RawFilePath, CUInt)]
getDirectoryContentsAndAttrs path = do
    resetErrno
{'fraction_non_alphanumeric': 0.08631984585741811, 'fraction_numerical': 0.0, 'mean_word_length': 3.0817610062893084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '778380', 'n_tokens_mistral': 762, 'n_tokens_neox': 758, 'n_words': 216}