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

Kevin Krammer krammer at kde.org
Wed Apr 17 12:23:26 PDT 2013


On Wednesday, 2013-04-17, Jan Kundrát wrote:
> On Friday, 12 April 2013 09:30:27 CEST, Kevin Krammer wrote:
> > I guess in your case you could use $XDG_CACHE_HOME (defaults to
> > $HOME/.cache)
> > and an application specific subdirectory.
> 
> I would like to expand on this a bit -- the application in question does
> maintain an on-disk cache, and if a file size exceeds certain threshold,
> it is saved as a regular file on disk. However, there are a couple of
> reasons for not making this cache visible to the user:
> 
> - There are no promises about the cache layout. It can change between the
> application versions without any further notice. Nothing else is expected
> to access it (think Akonadi's on-disk structures :) ).
> 
> - The files are optionally compressed.
> 
> - For technical reasons (the protocol provides hard guarantees about data
> immutability), the files shall really be read-only. If the user managed to
> e.g. open an office document from this private cache and saved it with
> some modifications, the appliocation would have to include extra
> checksumming, otherwise the next time user opens the "pristine attachment"
> from the IMAP server, they will actually see the modified data, and that's
> a serious bug.
> 
> - Tiny attachments might be saved in e.g. a sqlite database, not in an
> extra file.
> 
> This means that I cannot really use the already-present private cache and
> would have to come up with yet another custom location.

I wasn't suggesting to use an already existing cache (I didn't even know you 
had one). I just mentioned the existance of a location specifically intended 
for cached data.

Whether you copy the file from your internal cache to the location that you 
let the launched application see or whether you download it to that doesn't 
make any difference.

Just like you would have done with the temporary directory, only without 
problem of it being on a tmpfs filesystem, potentially allowing you to reuse 
the file (e.g. user clicking the attachment, closing the app shortly after, 
and clicking again).

Since it is still a cache location, you can always delete the file as you see 
fit, e.g. on next application start or if the file access time stamp is too 
old, etc.
In other words you don't have to delete it as soon as possible, thus nicely 
avoiding the problem of not knowing when the other application has opened it.

Cheers,
Kevin

-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/xdg/attachments/20130417/7cb56175/attachment.pgp>


More information about the xdg mailing list