Skip to content

Commit 22e02d0

Browse files
committed
effectiveRunDir uses Path
1 parent 35e8932 commit 22e02d0

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/Hledger/Flow/BaseDir.hs

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Hledger.Flow.BaseDir where
55

66
import Path
77
import Path.IO
8-
import Hledger.Flow.Types (HasBaseDir, HasRunDir, BaseDir, RunDir, baseDir, importRunDir)
8+
import Hledger.Flow.Types (HasBaseDir, BaseDir, RunDir, baseDir)
99
import Hledger.Flow.PathHelpers
1010

1111
import Data.Maybe
@@ -50,5 +50,10 @@ relativeToBase' bd p = if forceTrailingSlash bd == forceTrailingSlash p then "./
5050
turtleBaseDir :: HasBaseDir o => o -> TurtlePath
5151
turtleBaseDir opts = pathToTurtle $ baseDir opts
5252

53-
turtleRunDir :: HasRunDir o => o -> TurtlePath
54-
turtleRunDir opts = pathToTurtle $ importRunDir opts
53+
effectiveRunDir :: BaseDir -> RunDir -> Bool -> AbsDir
54+
effectiveRunDir bd rd useRunDir = do
55+
let baseImportDir = bd </> [Path.reldir|import|]
56+
let absRunDir = bd </> rd
57+
if useRunDir
58+
then if absRunDir == bd then baseImportDir else absRunDir
59+
else baseImportDir

src/Hledger/Flow/CSVImport.hs

+7-11
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import qualified Data.Text as T
1111
import qualified Data.List.NonEmpty as NonEmpty
1212
import qualified Hledger.Flow.Types as FlowTypes
1313
import Hledger.Flow.Import.Types
14-
import Hledger.Flow.BaseDir (turtleBaseDir, turtleRunDir, relativeToBase)
15-
import Hledger.Flow.PathHelpers (TurtlePath, forceTrailingSlash)
14+
import Hledger.Flow.BaseDir (relativeToBase, effectiveRunDir)
15+
import Hledger.Flow.PathHelpers (TurtlePath, pathToTurtle)
1616
import Hledger.Flow.DocHelpers (docURL)
1717
import Hledger.Flow.Common
1818
import Hledger.Flow.RuntimeOptions
@@ -39,26 +39,22 @@ inputFilePattern = Turtle.contains (Turtle.once (Turtle.oneOf pathSeparators) <>
3939

4040
importCSVs' :: RuntimeOptions -> TChan FlowTypes.LogMessage -> IO [TurtlePath]
4141
importCSVs' opts ch = do
42-
let baseImportDir = forceTrailingSlash $ (turtleBaseDir opts) </> "import"
43-
let runDir = forceTrailingSlash $ Turtle.collapse $ (turtleBaseDir opts) </> (turtleRunDir opts)
44-
let effectiveDir = if useRunDir opts
45-
then if (forceTrailingSlash $ runDir </> "import") == baseImportDir then baseImportDir else runDir
46-
else baseImportDir
47-
channelOutLn ch $ Turtle.format ("Collecting input files from "%Turtle.fp) effectiveDir
48-
(inputFiles, diff) <- Turtle.time $ Turtle.single . shellToList . onlyFiles $ Turtle.find inputFilePattern effectiveDir
42+
let effectiveDir = effectiveRunDir (baseDir opts) (importRunDir opts) (useRunDir opts)
43+
channelOutLn ch $ Turtle.format ("Collecting input files from "%Turtle.fp) $ pathToTurtle effectiveDir
44+
(inputFiles, diff) <- Turtle.time $ Turtle.single . shellToList . onlyFiles $ Turtle.find inputFilePattern (pathToTurtle effectiveDir)
4945
let fileCount = length inputFiles
5046
if (fileCount == 0) then
5147
do
5248
let msg = Turtle.format ("I couldn't find any input files underneath "%Turtle.fp
5349
%"\n\nhledger-flow expects to find its input files in specifically\nnamed directories.\n\n"%
54-
"Have a look at the documentation for a detailed explanation:\n"%Turtle.s) effectiveDir (docURL "input-files")
50+
"Have a look at the documentation for a detailed explanation:\n"%Turtle.s) (pathToTurtle effectiveDir) (docURL "input-files")
5551
errExit 1 ch msg []
5652
else
5753
do
5854
channelOutLn ch $ Turtle.format ("Found "%Turtle.d%" input files in "%Turtle.s%". Proceeding with import...") fileCount (Turtle.repr diff)
5955
let actions = map (extractAndImport opts ch) inputFiles :: [IO TurtlePath]
6056
importedJournals <- parAwareActions opts actions
61-
_ <- writeIncludesUpTo opts ch effectiveDir importedJournals
57+
_ <- writeIncludesUpTo opts ch (pathToTurtle effectiveDir) importedJournals
6258
_ <- writeToplevelAllYearsInclude opts
6359
return importedJournals
6460

0 commit comments

Comments
 (0)