From b627aa9c572411843b7cac12835c8cb89683e8ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 2 Jan 2024 14:36:14 -0500
Subject: [PATCH] data_transfer: avoid to crash if directory doesn't exist

This fix testReplayConversation

Change-Id: If760f08c31995a84c8818e1d0f4586865cfec5a9
---
 src/data_transfer.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/data_transfer.cpp b/src/data_transfer.cpp
index f6d3092237..884034aba1 100644
--- a/src/data_transfer.cpp
+++ b/src/data_transfer.cpp
@@ -553,9 +553,10 @@ TransferManager::onIncomingProfile(const std::shared_ptr<dhtnet::ChannelSocket>&
                     auto& pimpl = sthis_->pimpl_;
 
                     auto destPath = sthis_->profilePath(uri);
-                    {
+                    try {
                         // Move profile to destination path
                         std::lock_guard lock(dhtnet::fileutils::getFileLock(destPath));
+                        dhtnet::fileutils::recursive_mkdir(destPath.parent_path());
                         std::filesystem::rename(path, destPath);
                         if (!pimpl->accountUri_.empty() && uri == pimpl->accountUri_) {
                             // If this is the account profile, link or copy it to the account profile path
@@ -564,6 +565,8 @@ TransferManager::onIncomingProfile(const std::shared_ptr<dhtnet::ChannelSocket>&
                                 std::filesystem::copy_file(destPath, pimpl->accountProfilePath_, ec);
                             }
                         }
+                    } catch (const std::exception& e) {
+                        JAMI_ERROR("{}", e.what());
                     }
 
                     std::lock_guard lk {pimpl->mapMutex_};
-- 
GitLab