Skip to content

Commit

Permalink
fix:add,import,web: really avoid filenames ending with . on Windows [s…
Browse files Browse the repository at this point in the history
…imonmichael#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.
  • Loading branch information
simonmichael authored and adept committed Mar 8, 2024
1 parent 4a6736c commit 75ba17d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
2 changes: 1 addition & 1 deletion hledger-lib/Hledger/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions hledger/Hledger/Cli/Commands/Add.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).

0 comments on commit 75ba17d

Please sign in to comment.