The avatar cache is using not-atomic operation to store the image on-disk. This means when an avatar is updated, if more than on process is tracking its avatar data, they will both write the data into the cache at the same time. This is racy.
For now we could just create a QTemporaryFile then rename it. It's probably not 100% portable, but long-term solution is doing the cache in CM as said in bug #33410
Otherwise simple enough, but QFile::rename doesn't overwrite existing files. Looking at how similar tasks are implemented in KDE libraries could be a reasonable step forward.
I have to disable autoremove otherwise it remove the renamed file too :(