diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-17 12:22:24 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-17 12:22:24 +0900 |
commit | ada271e47071681848fdbdecd3aecaa9073091b4 (patch) | |
tree | 688b34a3437678897367a1774c429335140707d9 /room.cpp | |
parent | 038659c6997e5acad6ecf7171bbd3c4ec14b5d3d (diff) | |
download | libquotient-ada271e47071681848fdbdecd3aecaa9073091b4.tar.gz libquotient-ada271e47071681848fdbdecd3aecaa9073091b4.zip |
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).
Diffstat (limited to 'room.cpp')
-rw-r--r-- | room.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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)) { |