Skip to content

Instantly share code, notes, and snippets.

@m15k
Created December 9, 2014 20:29
Show Gist options
  • Save m15k/7190b78d63e88b0bc01d to your computer and use it in GitHub Desktop.
Save m15k/7190b78d63e88b0bc01d to your computer and use it in GitHub Desktop.
Assist with possible pipes safe issue on Win32
data Info = Info {
infoPath :: FilePath
, infoPerms :: Permissions
, infoSize :: Maybe Integer
, infoModTime :: UTCTime
, infoVariance :: Double
} deriving (Eq, Show, Ord)
-- | main executable function
-- will recurse through directories and unlock all the goodies
scanFileSystemPrototype :: FilePath -> ListT (SafeT IO) Info
scanFileSystemPrototype root = do
file <- recursiveContents (FP.decodeString root)
guard (filterData (FP.encodeString file))
perms <- liftIO (getPermissions (FP.encodeString file))
guard (readable perms) -- assert that file can be manipulated by executing account
liftIO (checkFile perms (FP.encodeString file))
where
checkFile fnAttr filename = do
size <- getFileSize filename
modified <- getModificationTime filename
vari <- computeVariance filename
fn <- absolutize filename
return $ Info fn fnAttr size modified vari
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment