betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

07 October 2015

Begone Mail... Not!!

There she goes

Yesterday evening I was writing a lengthy mail, explaining a nice little idea. The mail was written in English and Greek, spellchecked, re-read, corrected a bit, and then... the battery on the laptop suddenly ran out of steam and the laptop shut down unexpectedly. I didn't feel a single moment of anxiousness. I'm using mutt to handle my mails, and mutt hands off to vim to actually write my stuff. As I know quite well, vim saves temporary copies of my files, so in case of a crash, I'm often asked to recover files. Works quite well.

mutt saves unfinished mails in a "folder" called postponed. Since I had closed and re-opened the draft mail a couple of time, I expected find the unfinished mail there. But it wasn't. Lesson learned: mutt saves those mails there only when you close the message and postpone it. OK, so far, but no problem, since definitely vim had saved my message.

But I couldn't find it. It was gone. It started to take the wind out of my sails, since I had spend some time to make a beautiful little piece of mail, and the thought to do it all again demotivated me. I started going through my disk with a fine comb. I found the path where my files had been. I checked where vim is supposed to save temporary files (the "dir" setting directive), and the documentation gave me a strong hint to what had happened, for that setting the documentation suggested:

"Using "/tmp" on Unix is discouraged: When the system crashes
you lose the swap file"

Explanation: If you save your "swap" backup files in the /tmp directory, when you restart after your crash, the OS will go through /tmp and throw your carefully saved backup file away. This is what had happened to my mail. But why?

In my .vimrc, I hadn't changed the dir setting, and the default is to store files in a list of directories that are reasonably safe: ".,~/tmp,/var/tmp,/tmp". For a moment I was pointing fingers at vim, but it just doesn't make sense.

In fact the culprit is mutt: The mail program tells vim to "edit this file" and to store the needed temporary swap file in /tmp. There is a settings directive to change the place, but the default is the very unsafe /tmp directory. So my suggestion: if you use mutt, check your config to set the "tmpdir" directive to something safe, something where your OS will not clean up at restart time, e.g. on OpenBSD /tmp/vi.recover is spared from the knife.

Posted by betabug at 10:57 | Comments (0) | Trackbacks (0)