frozencemetery/haskey

Lazy IO is the worst

Closed this issue · 2 comments

Arguments to haskey are not evaluated until they are needed. This means that one may get partially through an operation only to have parsing fail. Worst case the database is lost.

That's really odd, I would have thought System.Console.GetOpt.getOpt handled that. Did you encounter a repro?

Me too. Anyway, I've tested on two machines now and:

(0) frozencemetery@kirtar:~$ cp .pw.db .pw.db.bak 
frozencemetery@kirtar:~$ haskey -c -P=18
Service:  sdf
Username: sdf
haskey: Prelude.read: no parse
frozencemetery@kirtar:~$ cat .pw.db
frozencemetery@kirtar:~$ mv ~/.pw.db.bak .pw.db
frozencemetery@kirtar:~$ file .pw.db
.pw.db: openssl enc'd data with salted password
frozencemetery@kirtar:~$ 

First-order fix is probably to make database modifications not be in-place (write out to another file, move it to replace the old one). Might also look at other parsers; optparse-applicative comes recommended highly.