Skip to content

Support distributions which clamp modified timestamps to epoch (LastModified == 0)

Jordan Pryde requested to merge prydom/ksvg:patch-findInCache into master

This patch resolves kf.plasma.core: findInCache with a lastModified timestamp of 0 is deprecated being logged whenever plasmashell encounters an SVG icon that is located in /usr on an OSTree-based distrobution.

OSTree-based OSs like Fedora Kinoite set all files modify date to epoch. For details about this design decision see https://ostreedev.github.io/ostree/repo/#content-objects.

I believe reproducible builds will also exhibit this behavior.

Based on:

    /**
     * TODO: timestamp shouldn't be user-provided
     * Check with file timestamp
     * where cache is still valid.
     *
     * @param key the name to use in the cache for this image
     * @param pix the pixmap object to populate with the resulting data if found
     * @param lastModified if non-zero, the time stamp is also checked on the file,
     *                     and must be newer than the timestamp to be loaded
     *
     * @note Since KF 5.75, a lastModified value of 0 is deprecated. If used, it
     *       will now always return false. Use a proper file timestamp instead
     *       so modification can be properly tracked.
     *
     * @return true when pixmap was found and loaded from cache, false otherwise
     **/
    bool findInCache(const QString &key, QPixmap &pix, unsigned int lastModified);

ImageSetPrivate::findInCache deprecates lastModified being set to zero because it thinks the caller may just be faking the value. KSvg is respecting the file's modify timestamp, which is legitimately set to 0, when caching. To signify we're not faking it we increment the timestamp by one.

I opted to increment the value on the caller side because I wanted to preserve the warning for caller who may not be respecting the lastModified argument's precondition that the timestamp is valid. Since I don't think a lastModified value of 0 causes any actual issues with the caching code, as an alternative we could instead reverse the deprecation.

Tested on Fedora Kinoite Rawhide (20240502.n.0). Resolves https://bugs.kde.org/show_bug.cgi?id=453876.

Merge request reports