Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.hledger.journal file overwritten on -f path typo #1056

Closed
ghost opened this issue Jun 23, 2019 · 11 comments
Closed

.hledger.journal file overwritten on -f path typo #1056

ghost opened this issue Jun 23, 2019 · 11 comments
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. docs Documentation-related. packaging Dependencies, version constraints, packaging.. platform:windows

Comments

@ghost
Copy link

ghost commented Jun 23, 2019

On Windows, the following command will overwrite the file Documents\.hledger.journal with an empty file. I sometimes make the typo with extra period in the path and I have to restore from backup. Version tested 1.14.1.

C:\Users\klacansky>hledger -f Documents.\.hledger.journal add
Creating hledger journal file C:\Users\klacansky\Documents.\.hledger.journal.
The hledger journal file "C:\Users\klacansky\Documents.\.hledger.journal" was not found.
Please create it first, eg with "hledger add" or a text editor.
Or, specify an existing journal file with -f or LEDGER_FILE.
@ghost ghost added the A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. label Jun 23, 2019
@simonmichael
Copy link
Owner

Wow, thanks for the report. Would you be interested in debugging further ? Help available in http://irc.hledger.org.

@simonmichael simonmichael added the needs:debugging To unblock: needs debugging/investigation label Jun 23, 2019
@ghost
Copy link
Author

ghost commented Jun 26, 2019

On IRC, we determined the issue is the directory ending with a period '.', windows ignores it, but hledger does not, thus it will report the file does not exists, and proceed to create a new file '.hledger.journal'. However, when creating that file, windows removes the period at the end of the directory name, and thus overwrites the original file.

@alerque
Copy link
Collaborator

alerque commented Jun 26, 2019

👏👏 Windows! When will you learn?

@simonmichael
Copy link
Owner

Ideas for resolution:

  • mention this issue for windows users in docs
  • on windows, check each part of the file path for a trailing period and warn or give an error
  • report this issue to the appropriate upstream haskell lib (base ?) and do the warning/error there

@simonmichael simonmichael removed the needs:debugging To unblock: needs debugging/investigation label Jun 26, 2019
@simonmichael simonmichael added packaging Dependencies, version constraints, packaging.. docs Documentation-related. labels Jun 26, 2019
@simonmichael
Copy link
Owner

I recommend prioritizing it; I were not to keep backup, it would really be upsetting

@simonmichael simonmichael reopened this Jun 26, 2019
@simonmichael
Copy link
Owner

simonmichael commented Jun 26, 2019

...you're right. I have pushed a fix. It should also be highlighted in docs (somewhere?) for users of older hledger versions. If someone wants to propagate this discussion to the upstream haskell lib, that might be a service to the community.

@simonmichael
Copy link
Owner

simonmichael commented Jun 26, 2019

I've mentioned this issue & requirement at the end of add's documentation (27c01e8). But I'm not sure this is enough. Is there somewhere else appropriate that users of older hledger might notice ?

@simonmichael
Copy link
Owner

I guess we could do this same path check for all commands (not just add and hledger-web add), which would make it more likely to be noticed before it actually causes trouble. But no.. this would require an up to date hledger version, which doesn't have the problem.

@simonmichael
Copy link
Owner

simonmichael commented Jun 26, 2019

So mention in next release notes and release announcement I guess. Adding it to the FAQ as well (even though it isn't one) might not hurt.

@ghost
Copy link
Author

ghost commented Jun 29, 2019

Thanks!

@ghost ghost closed this as completed Jun 29, 2019
simonmichael added a commit that referenced this issue Jan 5, 2024
…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.
adept pushed a commit to adept/hledger that referenced this issue Mar 8, 2024
…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.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. docs Documentation-related. packaging Dependencies, version constraints, packaging.. platform:windows
Projects
None yet
Development

No branches or pull requests

2 participants