From 6935dce4322946f5a6224fcab93e5384aa3952a0 Mon Sep 17 00:00:00 2001 From: Vaclav Svejcar Date: Mon, 9 Aug 2021 15:19:41 +0200 Subject: [PATCH] [#78] Add function to get user's home directory --- src/Headroom/IO/FileSystem.hs | 27 ++++++++++----------------- test/Headroom/Command/InitSpec.hs | 2 +- test/Headroom/Command/RunSpec.hs | 2 +- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Headroom/IO/FileSystem.hs b/src/Headroom/IO/FileSystem.hs index fdb0628..5b32f73 100644 --- a/src/Headroom/IO/FileSystem.hs +++ b/src/Headroom/IO/FileSystem.hs @@ -21,8 +21,8 @@ module Headroom.IO.FileSystem , FindFilesFn , FindFilesByExtsFn , FindFilesByTypesFn - , GetCacheDirectoryFn , GetCurrentDirectoryFn + , GetUserDirectoryFn , ListFilesFn , LoadFileFn -- * Polymorphic Record @@ -32,7 +32,6 @@ module Headroom.IO.FileSystem , findFiles , findFilesByExts , findFilesByTypes - , getCacheDirectory , listFiles , loadFile -- * Working with Files Metadata @@ -49,13 +48,12 @@ import Headroom.Data.Regex ( Regex import Headroom.FileType ( listExtensions ) import Headroom.FileType.Types ( FileType ) import RIO -import RIO.Directory ( XdgDirectory(..) - , createDirectory +import RIO.Directory ( createDirectory , doesDirectoryExist , doesFileExist , getCurrentDirectory , getDirectoryContents - , getXdgDirectory + , getHomeDirectory ) import RIO.FilePath ( isExtensionOf , takeExtension @@ -119,15 +117,16 @@ type FindFilesByTypesFn m -- ^ list of found files --- | Type of a function that obtains the cache directory as an absolute path. -type GetCacheDirectoryFn m = m FilePath - - -- | Type of a function that obtains the current working directory as an -- absolute path. type GetCurrentDirectoryFn m = m FilePath +-- | Type of a function that obtains the user's home directory as an absolute +-- path. +type GetUserDirectoryFn m = m FilePath + + -- | Type of a function that recursively find all files on given path. If file -- reference is passed instead of directory, such file path is returned. type ListFilesFn m @@ -164,10 +163,9 @@ data FileSystem m = FileSystem -- ^ Function that recursively finds files on given path by file extensions. , fsFindFilesByTypes :: FindFilesByTypesFn m -- ^ Function that recursively find files on given path by their file types. - , fsGetCacheDirectory :: GetCacheDirectoryFn m - -- ^ Function that obtains cache directory as an absolute path. , fsGetCurrentDirectory :: GetCurrentDirectoryFn m -- ^ Function that obtains the current working directory as an absolute path. + , fsGetUserDirectory :: GetUserDirectoryFn m , fsListFiles :: ListFilesFn m -- ^ Function that recursively find all files on given path. If file reference -- is passed instead of directory, such file path is returned. @@ -183,8 +181,8 @@ mkFileSystem = FileSystem { fsCreateDirectory = createDirectory , fsFindFiles = findFiles , fsFindFilesByExts = findFilesByExts , fsFindFilesByTypes = findFilesByTypes - , fsGetCacheDirectory = getCacheDirectory , fsGetCurrentDirectory = getCurrentDirectory + , fsGetUserDirectory = getHomeDirectory , fsListFiles = listFiles , fsLoadFile = loadFile } @@ -209,11 +207,6 @@ findFilesByTypes headersConfig types path = findFilesByExts path (types >>= listExtensions headersConfig) --- | Returns absolute path of the system preferred cache directory. -getCacheDirectory :: MonadIO m => GetCacheDirectoryFn m -getCacheDirectory = getXdgDirectory XdgCache "" - - -- | Recursively find all files on given path. If file reference is passed -- instead of directory, such file path is returned. listFiles :: MonadIO m => ListFilesFn m diff --git a/test/Headroom/Command/InitSpec.hs b/test/Headroom/Command/InitSpec.hs index 6b6386f..fae9ea7 100644 --- a/test/Headroom/Command/InitSpec.hs +++ b/test/Headroom/Command/InitSpec.hs @@ -80,8 +80,8 @@ env = TestEnv { .. } , fsFindFiles = undefined , fsFindFilesByExts = undefined , fsFindFilesByTypes = undefined - , fsGetCacheDirectory = undefined , fsGetCurrentDirectory = undefined + , fsGetUserDirectory = undefined , fsListFiles = undefined , fsLoadFile = undefined } diff --git a/test/Headroom/Command/RunSpec.hs b/test/Headroom/Command/RunSpec.hs index 1ec6b89..7a1df98 100644 --- a/test/Headroom/Command/RunSpec.hs +++ b/test/Headroom/Command/RunSpec.hs @@ -149,8 +149,8 @@ env = TestEnv { .. } , fsFindFiles = undefined , fsFindFilesByExts = undefined , fsFindFilesByTypes = undefined - , fsGetCacheDirectory = undefined , fsGetCurrentDirectory = undefined + , fsGetUserDirectory = undefined , fsListFiles = undefined , fsLoadFile = undefined }