From 7780221683adca49e3e336c38be82134ee8422fd Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 11 Jan 2021 11:14:51 +0100 Subject: [PATCH] Fixed "Single instance" locking issue on Linux with AppImage, where the PrusaSlicer binary is mounted at a different mount point at each AppImage execution. Fixes Lock files in the local configuration directory are not deleted (#5733) --- src/slic3r/GUI/InstanceCheck.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/InstanceCheck.cpp b/src/slic3r/GUI/InstanceCheck.cpp index 100fd5c530..552b891c55 100644 --- a/src/slic3r/GUI/InstanceCheck.cpp +++ b/src/slic3r/GUI/InstanceCheck.cpp @@ -252,14 +252,20 @@ namespace instance_check_internal bool instance_check(int argc, char** argv, bool app_config_single_instance) { -#ifndef _WIN32 - boost::system::error_code ec; -#endif - std::size_t hashed_path = + std::size_t hashed_path; #ifdef _WIN32 - std::hash{}(boost::filesystem::system_complete(argv[0]).string()); + hashed_path = std::hash{}(boost::filesystem::system_complete(argv[0]).string()); #else - std::hash{}(boost::filesystem::canonical(boost::filesystem::system_complete(argv[0]), ec).string()); + boost::system::error_code ec; +#ifdef __linux + // If executed by an AppImage, start the AppImage, not the main process. + // see https://docs.appimage.org/packaging-guide/environment-variables.html#id2 + const char *appimage_binary = std::getenv("APPIMAGE"); + if (appimage_binary) + hashed_path = std::hash{}(boost::filesystem::canonical(boost::filesystem::system_complete(appimage_binary, ec).string()); + if (ec.value() > 0) +#endif // __linux + hashed_path = std::hash{}(boost::filesystem::canonical(boost::filesystem::system_complete(argv[0]), ec).string()); if (ec.value() > 0) { // canonical was not able to find the executable (can happen with appimage on some systems. Does it fail on Fuse file systems?) ec.clear(); // Compose path with boost canonical of folder and filename @@ -269,7 +275,7 @@ bool instance_check(int argc, char** argv, bool app_config_single_instance) hashed_path = std::hash{}(boost::filesystem::system_complete(argv[0]).string()); } } -#endif // win32 +#endif // _WIN32 std::string lock_name = std::to_string(hashed_path); GUI::wxGetApp().set_instance_hash(hashed_path);