From 48620c8e8caeb387704b4edc2172c845e7028de0 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 15 Dec 2025 21:34:51 -1000 Subject: [PATCH] imp:journal:include: don't read file attributes unnecessarily When including a literal path, don't use the Glob library at all. Glob seems to read attributes of all files in a directory, which disturbs build tools like tup which detect dependencies based on filesystem operations. --- hledger-lib/Hledger/Read/JournalReader.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index e2cdab6cf..243b1bcde 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -388,19 +388,25 @@ includedirectivep iopts = do -- Make ** also match file name parts like zsh's GLOB_STAR_SHORT. let - expandedglob' = + finalglob = -- ** without a slash is equivalent to **/* case regexReplace (toRegex' $ T.pack "\\*\\*([^/\\])") "**/*\\1" expandedglob of Right s -> s Left _ -> expandedglob -- ignore any error, there should be none -- Compile as a Pattern. Can throw an error. - g <- case tryCompileWith compDefault{errorRecovery=False} expandedglob' of + pat <- case tryCompileWith compDefault{errorRecovery=False} finalglob of Left e -> customFailure $ parseErrorAt off $ "Invalid glob pattern: " ++ e Right x -> pure x -- Find all matched paths. These might include directories or the current file. - paths <- liftIO $ globDir1 g cwd + -- Glob seems to get attributes of all files in a directory, which disturbs build systems + -- which detect dependencies based on filesystem operations (eg tup). + -- So avoid using it if not needed. + paths <- liftIO $ + if isLiteral pat + then return $ if isAbsolute finalglob then [finalglob] else [cwd finalglob] + else globDir1 pat cwd -- Exclude any directories or symlinks to directories, and canonicalise, and sort. files <- liftIO $