aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-17 12:22:24 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-17 12:22:24 +0900
commitada271e47071681848fdbdecd3aecaa9073091b4 (patch)
tree688b34a3437678897367a1774c429335140707d9
parent038659c6997e5acad6ecf7171bbd3c4ec14b5d3d (diff)
downloadlibquotient-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).
-rw-r--r--room.cpp7
1 files changed, 5 insertions, 2 deletions
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))
{