Skip to content

Commit

Permalink
Generalize finder
Browse files Browse the repository at this point in the history
  • Loading branch information
willbasky committed Oct 20, 2019
1 parent 5cf79fc commit 140a75d
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions ff-core/lib/FF.hs
Expand Up @@ -628,22 +628,18 @@ getDataDir :: Config -> IO DataDirectory
getDataDir Config {dataDir} = do
cur <- getCurrentDirectory
let directories = parents cur
vcsPath <- findVcs directories
ffPath <- findFF directories
getDataDirectory vcsPath ffPath
ffPathNew <- findPath directories ".git"
ffPath <- findPath directories ".ff"
getDataDirectory ffPathNew (ffPath <|> dataDir)
where
parents = reverse . scanl1 (</>) . splitDirectories . normalise
findVcs [] = pure Nothing
findVcs (dir : dirs) = do
isDirVcsGit <- doesDirectoryExist (dir </> ".git")
if isDirVcsGit then pure $ Just (dir </> ".ff") else findVcs dirs
findFF [] = pure dataDir
findFF (dir : dirs) = do
isDirFF <- doesDirectoryExist (dir </> ".ff")
if isDirFF then pure $ Just (dir </> ".ff") else findFF dirs
getDataDirectory vcsPath ffPath
| (length <$> vcsPath) > (length <$> ffPath) = pure $
DataDirectory{vcsRequired = vcsPath, vcsNotRequired = ffPath}
findPath [] _ = pure Nothing
findPath (dir : dirs) path = do
isPath <- doesDirectoryExist (dir </> path)
if isPath then pure $ Just (dir </> ".ff") else findPath dirs path
getDataDirectory ffPathNew ffPath
| (length <$> ffPathNew) > (length <$> ffPath) = pure $
DataDirectory{vcsRequired = ffPathNew, vcsNotRequired = ffPath}
| otherwise = pure $
DataDirectory{vcsRequired = Nothing, vcsNotRequired = ffPath}

Expand Down

0 comments on commit 140a75d

Please sign in to comment.