4

In Firefox, when I choose to open a file without saving it and without an internal plugin (like a pdf or a doc file) the default behavior is that the file is saved in /tmp as a temporary file and that the chosen application (like mupdf or libreoffice) is opened with the temporary file as input. The filename of the temporary file is usually the original name of the downloaded file, unless a file with the same name is already present in /tmp. In such case, a suffix is appended to the filename (-1, -2, -3, etc) before its extension. The temporary files are deleted from /tmp when Firefox is closed (unless the default behavior is changed).

I think it would be much more convenient to delete each temporary file when it is not needed anymore (i.e., when the application using it stops using it). Is there a way to implement this?

As an alternative, a better behavior for me would be to replace the existing file in /tmp with the new one in case a file with the same name already exists? (i.e., without changing the filename). Is this possible?

2

To delete the temporary file as soon as possible, you can write a wrapper, like:

#!/bin/sh
the-application "$1"
rm -f "$1"

replacing the-application by the name of the real executable, and ask Firefox to use this wrapper instead of the application. Or:

#!/bin/sh
the-application "$1"
case "$1" in
  /tmp/*) rm -f "$1" ;;
esac

This form is safer in case future Firefox versions do not create a new file for "file:" URL's (you don't want the file to be removed in this case).

Note that some applications return immediately and may fail to work correctly if the file is removed before the application is quit. In such a case, there isn't much you can do (at least in a reliable way).

Concerning the alternative (to replace an existing file with the same name), this can yield clashes with other applications that use /tmp, with possible security implications. This is not a good idea in general.

| improve this answer | |
  • Apparently, this is the solution for my problem. Unexpectedly, it works also for applications which return immediately (such as libreoffice when another libreoffice windows is already open). – Daniele Jan 16 '15 at 10:26
  • @Daniele Yes, an application should not return before the file has been opened, and once this is done, everything is safe until the file descriptor is closed (but some applications reopen the file after closing it, so that they will fail). The rm command itself does not remove the file. It just unlinks it, i.e. it removes only the name, not the contents. The actual file is deleted by the system only when there are no longer any references to it (another name on the file system or an open file descriptor). – vinc17 Jan 16 '15 at 12:45
1

I've been sitting in Firefox parameters for some time and they really look ugly. But! In your example, there is a simple solution. First, you must create your own script to include setting temporary path, then running browser, and finally removing files from temporary path This would look like #!/bin/bash tmp_folder='/tmp/firefox-tmp' export TMP=$tmp_folder export TEMP=$tmp_folder # (my Iceweasel needs setting both TMP and TEMP!) mkdir $tmp_folder firefox rm -f $tmp_folder/* Save this file somewhere (on desktop like: /home//Desktop/firefox.sh and grant execute permission with chmod +x full_path_to_file_on_desktop Right now, when you run script, you will redirect all temporary files as you needed to this /tmp/firefox-tmp folder, and once browser is closed, folder content is removed. TIP: I haven't fount any settings in Firefox (about:config) to change default behaviour as you faces, so please use my solution. It really works :) You could also play with user profiles and cache profiles, but that's a topic for another...yyy...topic ;)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.