From 75ba17da913443260510c27e286b963624a70542 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 4 Jan 2024 17:27:53 -1000 Subject: [PATCH] fix:add,import,web: really avoid filenames ending with . on Windows [#1056] On MS Windows, trying to add or import or web add to a file whose name ends with a dot could cause data loss, so in 2019 I made this raise an error instead (in Hledger.Read.ensureJournalFileExists). But, the logic was backward, so it did not do the check on Windows. Now it does. Also I have removed mention of this from add's doc; currently it's not documented anywhere. It's obscure, but maybe this is not ideal. --- hledger-lib/Hledger/Read.hs | 2 +- hledger/Hledger/Cli/Commands/Add.md | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index 530c26483994..ea96b7547d59 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -348,7 +348,7 @@ requireJournalFileExists f = do -- which could cause data loss (see 'isWindowsUnsafeDotPath'). ensureJournalFileExists :: FilePath -> IO () ensureJournalFileExists f = do - when (os/="mingw32" && isWindowsUnsafeDotPath f) $ do + when (os=="mingw32" && isWindowsUnsafeDotPath f) $ do hPutStr stderr $ "Part of file path \"" <> show f <> "\"\n ends with a dot, which is unsafe on Windows; please use a different path.\n" exitFailure exists <- doesFileExist f diff --git a/hledger/Hledger/Cli/Commands/Add.md b/hledger/Hledger/Cli/Commands/Add.md index 85c3d6da2a54..1405e98bc080 100644 --- a/hledger/Hledger/Cli/Commands/Add.md +++ b/hledger/Hledger/Cli/Commands/Add.md @@ -67,7 +67,3 @@ and you have declared a default commodity with a `D` directive, you might expect `add` to add this symbol for you. It does not do this; we assume that if you are using a `D` directive you prefer not to see the commodity symbol repeated on amounts in the journal. - -On Microsoft Windows, the add command makes sure that no part of the -file path ends with a period, as that would cause problems -([#1056](https://github.com/simonmichael/hledger/issues/1056)).