From e8f9139afdfbe3c0f96f88fda8ea5139cfcfdbaf Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Wed, 12 Jun 2024 11:09:39 -0400
Subject: [PATCH] fileutils: add more logs, use error code instead of
 exceptions

GitLab: #972
Change-Id: Ie41b6b32bf9ed2764e86b8cb43ba6aedb9ec6a28
---
 src/fileutils.cpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/fileutils.cpp b/src/fileutils.cpp
index ea26aecaa1..d159a03944 100644
--- a/src/fileutils.cpp
+++ b/src/fileutils.cpp
@@ -187,11 +187,13 @@ isDirectoryWritable(const std::string& directory)
 bool
 createSymlink(const std::filesystem::path& linkFile, const std::filesystem::path& target)
 {
-    try {
-        std::filesystem::create_symlink(target, linkFile);
-    } catch (const std::exception& e) {
-        JAMI_ERR("Couldn't create soft link: %s", e.what());
+    std::error_code ec;
+    std::filesystem::create_symlink(target, linkFile, ec);
+    if (ec) {
+        JAMI_WARNING("Couldn't create soft link from {} to {}: {}", linkFile, target, ec.message());
         return false;
+    } else {
+        JAMI_LOG("Created soft link from {} to {}", linkFile, target);
     }
     return true;
 }
@@ -199,11 +201,13 @@ createSymlink(const std::filesystem::path& linkFile, const std::filesystem::path
 bool
 createHardlink(const std::filesystem::path& linkFile, const std::filesystem::path& target)
 {
-    try {
-        std::filesystem::create_hard_link(target, linkFile);
-    } catch (const std::exception& e) {
-        JAMI_ERR("Couldn't create hard link: %s", e.what());
+    std::error_code ec;
+    std::filesystem::create_hard_link(target, linkFile, ec);
+    if (ec) {
+        JAMI_WARNING("Couldn't create hard link from {} to {}: {}", linkFile, target, ec.message());
         return false;
+    } else {
+        JAMI_LOG("Created hard link from {} to {}", linkFile, target);
     }
     return true;
 }
-- 
GitLab