Skip to content

Commit a4ec28f

Browse files
committed
effectiveRunDir uses Path
1 parent 86a8cf1 commit a4ec28f

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
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

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# resolver: ./custom-snapshot.yaml
2020
# resolver: https://example.com/snapshots/2018-01-01.yaml
21-
resolver: nightly-2020-08-10
21+
resolver: nightly-2020-08-27
2222

2323
# User packages to be built.
2424
# Various formats can be used as shown in the example below.

stack.yaml.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
packages: []
77
snapshots:
88
- completed:
9-
size: 520653
10-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/8/10.yaml
11-
sha256: 2e0c7e242a3b8cbc6f9027f03c7aeaa5609c82bcc40e2b00b7fa9c4d1269ddcd
12-
original: nightly-2020-08-10
9+
size: 523649
10+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/8/27.yaml
11+
sha256: 95012648db1b2180e3d7e0a3d44bc2a61b6854028382674724fee7ffa24300c3
12+
original: nightly-2020-08-27

0 commit comments

Comments
 (0)