diff --git a/src/fileutils.cpp b/src/fileutils.cpp
index 57ace9fc026e3001397bfe8f1a8dc059622c7b88..43eaef1faa722ed0de325aef9cba210475fd786d 100644
--- a/src/fileutils.cpp
+++ b/src/fileutils.cpp
@@ -928,16 +928,17 @@ eraseFile_win32(const std::string& path, bool dosync)
 bool
 eraseFile_posix(const std::string& path, bool dosync)
 {
-    int fd = open(path.c_str(), O_WRONLY);
-    if (fd == -1) {
-        JAMI_WARN("Can not open file %s for erasing.", path.c_str());
+    struct stat st;
+    if (stat(path.c_str(), &st) == -1) {
+        JAMI_WARN("Can not erase file %s: fstat() failed.", path.c_str());
         return false;
     }
+    // Remove read-only flag if possible
+    chmod(path.c_str(), st.st_mode | (S_IWGRP+S_IWUSR) );
 
-    struct stat st;
-    if (fstat(fd, &st) == -1) {
-        JAMI_WARN("Can not erase file %s: fstat() failed.", path.c_str());
-        close(fd);
+    int fd = open(path.c_str(), O_WRONLY);
+    if (fd == -1) {
+        JAMI_WARN("Can not open file %s for erasing.", path.c_str());
         return false;
     }
 
diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp
index b26aa7a6f4c3ebaad1486094846cfe3694175bf4..18ba622ee2844045ab589aeb1b49ea3807010ce5 100644
--- a/src/jamidht/conversationrepository.cpp
+++ b/src/jamidht/conversationrepository.cpp
@@ -2589,7 +2589,7 @@ ConversationRepository::cloneConversation(const std::shared_ptr<JamiAccount>& ac
     if (fileutils::isDirectory(path)) {
         // If a crash occurs during a previous clone, just in case
         JAMI_WARNING("Removing existing directory {} (the dir exists and non empty)", path);
-        if (!fileutils::removeAll(path, true))
+        if (fileutils::removeAll(path, true) != 0)
             return nullptr;
     }