Saving in /tmp is not really saving

firefoxlibreofficetmp

Open e.g. a mail attachment from Firefox (without previously saving it); this is a Libre Office document, you edit it, and then push save (not save as) and close both text editor and browser. Then the document disappears, as it was stored by default in /tmp. At least this is the case on my Ubuntu 12.04.

Do you think this is the correct behavior? Shouldn't the program at least remind you that you're not really saving anything? or is there some way to recover the file (also after logout and/or reboot)?

Best Answer

Playing around with this I find that when you choose to open a document with an external program in Firefox, what happens is that Firefox downloads the program to /tmp and then runs the chosen program with the downloaded file as an argument (read 'opens the file with the chosen program').

If you then save the file (without choosing Save As or the equivalent) from within the program, it will use this file in /tmp.

Firefox will clean up these temporary files when it closes. So you can recover the file if you close LibreOffice, but not Firefox. However, as soon as Firefox is closed, the file will be deleted.

On most (all?) distros, the /tmp folder will also be emptied on reboot (files in /var/tmp should persist for longer).

Note also that this behaviour is only for 'opening' a file with an external program. If the file is opened internally via a plugin or otherwise, then it appears /tmp is not used (the file appears to be cached elsewhere along with the web pages themselves).

Update

For reference (I don't recommend doing this unless it is necessary), you can disable the deleting of /tmp on files when firefox closes using the browser.helperApps.deleteTempFileOnExit option. This can be set via the about:config page (just type this in the address bar and press enter). If it exists and is false, just right click on it and choose toggle. Otherwise, add it by doing Right Click->New->Boolean, then enter the name of the option and choose false.

To store /tmp files past the next reboot on recent Debian based systems, first look at /etc/default/tmpfs and make sure the is no RAMTMP=yes line. If it is commented out (# at the start), this is fine (if it was set then /tmp would be on a tmpfs filesystem in memory and would not be stored on disk). Next add or change the TMPTIME line in /etc/default/rcS. To store /tmp files indefinitely you can do:

TMPTIME=infinite

Or you can use a positive number instead of infinite to keep them for that number of days, once their time is up they will be deleted at the next reboot. Obviously if this line is commented out, uncomment it.

Related Question