From bbe2adc44fe9d404621d54efd3edef0c7fe493cf Mon Sep 17 00:00:00 2001 From: ilya-fedin Date: Tue, 26 May 2020 16:13:38 +0400 Subject: [PATCH] Fix AppImage overwrite by updater --- Telegram/SourceFiles/_other/updater_linux.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Telegram/SourceFiles/_other/updater_linux.cpp b/Telegram/SourceFiles/_other/updater_linux.cpp index d56478ba28..5d4d742e2f 100644 --- a/Telegram/SourceFiles/_other/updater_linux.cpp +++ b/Telegram/SourceFiles/_other/updater_linux.cpp @@ -298,6 +298,28 @@ bool update() { for (size_t i = 0; i < from.size(); ++i) { string fname = from[i], tofname = to[i]; + + // it is necessary to remove the old file to not to get an error if appimage file is used by fuse + struct stat statbuf; + writeLog("Trying to get stat() for '%s'", tofname.c_str()); + if (!stat(tofname.c_str(), &statbuf)) { + if (S_ISDIR(statbuf.st_mode)) { + writeLog("Fully clearing path '%s'..", tofname.c_str()); + if (!remove_directory(tofname.c_str())) { + writeLog("Error: failed to clear path '%s'", tofname.c_str()); + delFolder(); + return false; + } + } else { + writeLog("Unlinking file '%s'", tofname.c_str()); + if (unlink(tofname.c_str())) { + writeLog("Error: failed to unlink '%s'", tofname.c_str()); + delFolder(); + return false; + } + } + } + writeLog("Copying file '%s' to '%s'..", fname.c_str(), tofname.c_str()); int copyTries = 0, triesLimit = 30; do {