From ada271e47071681848fdbdecd3aecaa9073091b4 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 17 Jan 2018 12:22:24 +0900 Subject: Room::downloadFile(): make sure temporary file names don't clash Particularly in case when there are two events that have an image with the same file name (image.png). --- room.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'room.cpp') diff --git a/room.cpp b/room.cpp index d1b098e7..bec4cd30 100644 --- a/room.cpp +++ b/room.cpp @@ -837,11 +837,14 @@ void Room::downloadFile(const QString& eventId, const QUrl& localFilename) return; } auto* fileInfo = event->content()->fileInfo(); + auto safeTempPrefix = eventId; + safeTempPrefix.replace(':', '_'); + safeTempPrefix = QDir::tempPath() + '/' + safeTempPrefix + '#'; auto fileName = !localFilename.isEmpty() ? localFilename.toLocalFile() : !fileInfo->originalName.isEmpty() ? - (QDir::tempPath() + '/' + fileInfo->originalName) : + (safeTempPrefix + fileInfo->originalName) : !event->plainBody().isEmpty() ? - (QDir::tempPath() + '/' + event->plainBody()) : QString(); + (safeTempPrefix + event->plainBody()) : QString(); auto job = connection()->downloadFile(fileInfo->url, fileName); if (isJobRunning(job)) { -- cgit v1.2.3