Direct-opening a temporary file using the user's preferred application

David Faure faure at kde.org
Fri Apr 19 10:23:18 PDT 2013


On Wednesday 03 April 2013 16:05:56 Jan Kundrát wrote:
> The alternative is to leave these files laying around and rely on some
> automatic cleanup of the temporary files. This smells an unreliable thing
> to me. Waiting for xdg-open to finish (or even for the launched binary to
> finish, or...) is not the way to go because many applications like
> LibreOffice use a shared process which handles multiple documents, so
> there's no guarantee that the launched app exits when the file is no longer
> needed, nor that it is not needed anymore after the process exits.
> 
> Pointers on how to do this in a reliable way are much welcome.

I implemented a solution to this in KDE applications (since 3.4, in 2004).

Those that have in their .desktop the line
X-KDE-HasTempFileOption=true
support the command-line option --tempfile, documented as
"The files/URLs opened by the application will be deleted after use".

This allows the application itself to choose when to delete the temp file. For 
instance konqueror does that when closing the tab that displays the file.

This is typically used by email clients, which use temp files to save 
attachments (from email data) before launching apps.

For apps that don't support such an option, we launch a watcher executable 
(kioexec --tempfiles command...)  which deletes the temp file once the app 
exits, after a 3 minutes delay. kioexec exits afterwards.
The 3 minutes give enough time to apps who fork on startup (like libreoffice 
or amarok) to read the file on startup before it gets deleted (more details in 
KDE bug 130709, says the kioexec code).

Maybe this --tempfile option solution could be standardized, if others see 
value in it.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5



More information about the xdg mailing list