Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Show SculptForge on Discord: gone when you quit; after Restart to update the old AppImage quits; outline cube icon
islandmed99534ea31b54
diff --git a/CMakeLists.txt b/CMakeLists.txtindex c5d4a32a..e2dd2ee5 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -159,6 +159,7 @@ add_library(sculptforge_core STATICsrc/core/LitSphere.cppsrc/core/Trash.cppsrc/core/DiscordPresence.cpp+ src/core/ExitWatchdog.cppsrc/core/Project.cppsrc/core/Guide.cppsrc/core/WhatsNew.cppdiff --git a/changes/fix-presence-on-exit.md b/changes/fix-presence-on-exit.mdnew file mode 100644index 00000000..b7558d60--- /dev/null+++ b/changes/fix-presence-on-exit.md@@ -0,0 +1,21 @@+---+whats_new: After **Restart to update** on Linux, the previous version quits instead of staying hidden in the background (it kept showing SculptForge on Discord). Discord shows the outline cube icon.+fixed: Linux AppImage: after Restart to update, the previous version hid its window and never quit, so it kept running+ in the background (and, with Show SculptForge on Discord on, kept "Playing SculptForge" on your profile after you+ closed SculptForge). It now quits as soon as the new version is up. Updating from 0.11.10 or earlier, the new+ version ends the previous one itself (thanks @ebarranco).+fixed: Show SculptForge on Discord: quitting clears it first and it never comes back during the teardown; a quit that+ stalls ends the process after 15 s; the status shows the outline cube icon instead of the old SF letters.+testers:+ - Linux AppImage from 0.11.10 with Show SculptForge on Discord on: Help > Check for updates, Restart to update.+ After the new version opens, System Monitor shows one SculptForge; close it: nothing left, Discord status gone.+ - The same with Discord off: still only one SculptForge after the update, none after closing it.+ - Any OS: Preferences > Integrations > Show SculptForge on Discord on; profile shows the orange outline cube. Close the+ window: the status goes within a few seconds.+---+Cause: tickSelfUpdate (the old version watching for the new one, with a 90 s deadline) ran only in drawUpdateBanner,+i.e. on drawn frames; the old version hides its window for the restart, gets no events and draws nothing, so it never+checked and never quit. Now also on the passes that draw nothing (App::run). For 0.11.0-0.11.10 (old code), the new version+SIGTERMs its parent once it has started, only when that is sculptforge from the same AppImage file, same user+(update::isOldAppImage). The Rich Presence image is a new, frozen URL (press/sculptforge-app-icon-cube-outline-1024.png):+the PNG must be live (site lane) before the app ships.diff --git a/src/app/App.cpp b/src/app/App.cppindex 754ad0f1..8f398124 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -336,9 +336,12 @@ void App::shutdown() {SDL_Quit();return;}+ // First: clears what Discord shows, then closes. Never made again: endStroke and the rest of the teardown+ // update the title, which used to start a new client that showed SculptForge again while quitting (@ebarranco).+ discordClosed_ = true;+ discordClient_.reset();saveWindowState();autosavePrefs(true); // a change still waiting for its moment- discordClient_.reset(); // clears what Discord shows, then closesif (doc_.sculptor.strokeActive()) endStroke();solver_.reset(); // (its thread uses the renderer)flushBrushEdits();@@ -1159,13 +1162,20 @@ int App::run() {redrawAt_ = 0.0;draw = true;}- if (!draw && !continuous && !wantsFrames(t)) continue;+ // No frame: the update still ticks (drawUpdateBanner, on frames). After Restart to update this version hides+ // its window and draws nothing, yet must see the new version start (or its deadline) and quit; it never did,+ // and kept running hidden, "Playing SculptForge" on Discord (@ebarranco, 0.11.1 -> 0.11.10).+ if (!draw && !continuous && !wantsFrames(t)) {+ tickSelfUpdate();+ continue;+ }int fbW = 0, fbH = 0, winW = 0, winH = 0;SDL_GetWindowSizeInPixels(window_, &fbW, &fbH);SDL_GetWindowSize(window_, &winW, &winH);if (fbW <= 0 || fbH <= 0) {draw = false; // minimised: the next event (restore) draws again+ tickSelfUpdate();continue;}if (measuring) cpuFrameStart = processCpuSeconds();diff --git a/src/app/App.h b/src/app/App.hindex 3a40e705..8c002998 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -549,6 +549,7 @@ private:struct DiscordClientDelete { void operator()(discord::Client* c) const; };DiscordPresencePrefs discordPrefs_;std::unique_ptr<discord::Client, DiscordClientDelete> discordClient_; // made on the first switch-on+ bool discordClosed_ = false; // quitting: cleared and closed, never made again (shutdown)int64_t discordStart_ = 0; // seconds since 1970 when this session started (the elapsed time)char discordChallengeBuf_[64 * 4 + 1] = {}; // the theme field (64 code points of UTF-8)bool discordPresenceAvailable() const; // an application ID is compiled in@@ -1555,6 +1556,7 @@ private:// when it doesn't) or when the app quits (Later). Package-managed installs get their command instead.enum class SelfUpdateStage { Idle, Downloading, Ready, Restarting, Failed };void initSelfUpdate(); // initProject: a just-installed version counts its start (and rolls back a broken one)+ void endOldAppImage(); // Linux AppImage: the version that restarted into this one quits (0.11.10 and earlier stayed)void tickSelfUpdate(); // each frame: confirms this version is up, watches a restartbool drawSelfUpdate(const UpdateInfo& u, bool& close); // the banner's Update row; true: it replaces the usual buttonsbool selfUpdateOffered(const UpdateInfo& u);diff --git a/src/app/PanelIntegrations.cpp b/src/app/PanelIntegrations.cppindex 977dfc7b..aa2e87bb 100644--- a/src/app/PanelIntegrations.cpp+++ b/src/app/PanelIntegrations.cpp@@ -31,7 +31,7 @@ bool App::discordAgentRun() const {void App::updateDiscordPresence() {// Scripted and agent runs (benchmarks, offscreen checks, the Windows PC's runs) use the user's preferences too:// they never show up on the user's Discord.- if (!discordPresenceAvailable() || supportCardTestMode() || discordAgentRun()) return;+ if (!discordPresenceAvailable() || supportCardTestMode() || discordAgentRun() || discordClosed_) return;if (!discordPrefs_.enabled && !discordClient_) return; // never switched on: no thread, no connectionif (!discordClient_) discordClient_.reset(new discord::Client(discord::kDiscordAppId));if (discordStart_ == 0)diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex 82b5a7dc..167753ad 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -858,7 +858,7 @@ void App::pollUpdateCheck() {void App::drawUpdateBanner() {pollUpdateCheck(); // (here, not in tickProject: this runs every frame, UI tests included)- tickSelfUpdate();+ tickSelfUpdate(); // (and in run() on the passes that draw nothing: asleep, hidden for a restart)if (!updateAvailable_) return;const UpdateInfo& u = *updateAvailable_;const CanvasRect c = canvasRect(); // top centre of the 3D view, clear of the shelvesdiff --git a/src/app/PanelUpdate.cpp b/src/app/PanelUpdate.cppindex 38f0e7f4..f37f219a 100644--- a/src/app/PanelUpdate.cpp+++ b/src/app/PanelUpdate.cpp@@ -25,6 +25,10 @@#define NOMINMAX#include <windows.h> // GetCurrentProcessId#endif+#if defined(__linux__)+#include <csignal> // kill (endOldAppImage)+#include <unistd.h>+#endifnamespace sf {@@ -162,6 +166,19 @@ void App::initSelfUpdate() {}}+// Linux AppImage, after Restart to update: SculptForge 0.11.10 and earlier, hidden while waiting, never noticed the+// new version start and kept running (tickSelfUpdate ran only on drawn frames). The new version ends it: its parent+// is that version (AppRun is the program itself) when it runs our same AppImage file (update::isOldAppImage).+void App::endOldAppImage() {+#if defined(__linux__)+ const char* appImage = std::getenv("APPIMAGE");+ const pid_t parent = getppid();+ if (!appImage || !*appImage || parent <= 1 || !update::isOldAppImage("/proc/" + std::to_string(parent), appImage)) return;+ SDL_Log("update: the previous version (process %d) is still running; ending it", int(parent));+ kill(parent, SIGTERM); // SDL: a quit, as if its window were closed (its changes were saved before the restart)+#endif+}+void App::tickSelfUpdate() {if (memberSignIn_ && memberSignIn_->done) {const std::shared_ptr<MemberSignIn> job = std::move(memberSignIn_);@@ -183,6 +200,7 @@ void App::tickSelfUpdate() {if (confirmStartAt_ > 0.0 && nowSeconds() >= confirmStartAt_) {confirmStartAt_ = 0.0;update::confirmStarted(updateNotePath()); // (the old version, watching, sees the note go and quits)+ endOldAppImage();}if (selfUpdateStage_ == SelfUpdateStage::Downloading && selfUpdate_ && selfUpdate_->done) {if (selfUpdate_->ok) {@@ -211,6 +229,8 @@ void App::tickSelfUpdate() {SDL_Log("update: %s exited with %d before it was up; %s", selfUpdateVersion_.c_str(), code,restored ? "the previous version is back" : error.c_str());if (window_) SDL_ShowWindow(window_);+ discordClosed_ = false; // this version carries on: back on Discord, if it's on+ updateDiscordPresence();selfUpdateStage_ = SelfUpdateStage::Failed;selfUpdateError_ = restored ? "SculptForge " + selfUpdateVersion_ + " didn't start, so this version was kept": "SculptForge " + selfUpdateVersion_ + " didn't start: " + error;@@ -318,6 +338,10 @@ void App::restartIntoUpdate() {}selfUpdateStage_ = SelfUpdateStage::Restarting;if (restartChild_ && window_) SDL_HideWindow(window_); // (shown again if the new version doesn't start)+ if (restartChild_) { // hidden: the new version shows itself on Discord (if it's on), never both+ discordClosed_ = true;+ discordClient_.reset();+ }});}diff --git a/src/app/main.cpp b/src/app/main.cppindex 3781eae5..b50b088b 100644--- a/src/app/main.cpp+++ b/src/app/main.cpp@@ -8,6 +8,7 @@#include "app/UiServe.h"#include "ai/AiPolicy.h"#include "core/Benchmark.h"+#include "core/ExitWatchdog.h"#include "core/Wavelet.h"#include "core/FocusDetail.h"#include "core/Pack.h"@@ -170,6 +171,8 @@ int finishIsolated(int code) {std::abort();}+static bool g_uiServe = false; // --ui-serve: runMain runs once per script in one process+// One run of the app: the whole of main, also each script of the warm UI test server (--ui-serve, UiServe.cpp).static int runMain(int argc, char** argv) {sf::AppOptions options;@@ -332,6 +335,9 @@ static int runMain(int argc, char** argv) {const auto runStart = std::chrono::steady_clock::now();int code = app->run();const auto runEnd = std::chrono::steady_clock::now();+ // Quitting always ends the process, even if a driver or thread stalls the teardown or the exit (core/ExitWatchdog.h).+ // --ui-serve runs the next script in this process: never there.+ if (!g_uiServe) sf::armExitWatchdog(15000, code);app->shutdown();app.reset();if (std::getenv("SF_STARTUP_TIMES"))@@ -360,6 +366,9 @@ int main(int argc, char** argv) {#ifndef _WIN32if (argc >= 2 && std::string(argv[1]) == "--cli") return execCli(argc, argv);#endif- if (argc >= 2 && std::string(argv[1]) == "--ui-serve") return sf::runUiServer(argc - 1, argv + 1, runMain);+ if (argc >= 2 && std::string(argv[1]) == "--ui-serve") {+ g_uiServe = true;+ return sf::runUiServer(argc - 1, argv + 1, runMain);+ }return runMain(argc, argv);}diff --git a/src/core/DiscordPresence.h b/src/core/DiscordPresence.hindex 4050429f..1aed7fcb 100644--- a/src/core/DiscordPresence.h+++ b/src/core/DiscordPresence.h@@ -30,9 +30,10 @@ namespace sf::discord {// The SculptForge application on Discord's developer portal (a public ID, not a secret). "0" hides the feature and// never connects.inline constexpr const char* kDiscordAppId = "1567737303210926130";-// The icon: the cube app icon on the site (Discord fetches an external image through its media proxy; the portal's-// "logo" asset was a placeholder cube).-inline constexpr const char* kLargeImageUrl = "https://sculptforge.app/press/sculptforge-icon-1024.png";+// The icon: the outline cube app icon on the site. Discord's media proxy caches an external image by its URL, so+// this file never changes: a new icon gets a new file name (sculptforge-icon-1024.png changed, yet Discord kept+// showing the SF mark; @ebarranco). tests/test_discord_presence.cpp pins its content.+inline constexpr const char* kLargeImageUrl = "https://sculptforge.app/press/sculptforge-app-icon-cube-outline-1024.png";// A run made by a script or an agent, never the user at the window: SDL_APP_ID=sculptforge-agent,// SDL_VIDEO_DRIVER=offscreen (or videoDriver "offscreen") or SF_NO_DISCORD set. It never shows anything on thediff --git a/src/core/ExitWatchdog.cpp b/src/core/ExitWatchdog.cppnew file mode 100644index 00000000..e6774744--- /dev/null+++ b/src/core/ExitWatchdog.cpp@@ -0,0 +1,33 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "core/ExitWatchdog.h"++#include <chrono>+#include <cstdio>+#include <thread>++#if defined(_WIN32)+#ifndef NOMINMAX+#define NOMINMAX+#endif+#include <windows.h>+#else+#include <unistd.h>+#endif++namespace sf {++void armExitWatchdog(int timeoutMs, int code, std::function<void()> onTimeout) {+ std::thread([timeoutMs, code, onTimeout = std::move(onTimeout)] {+ std::this_thread::sleep_for(std::chrono::milliseconds(timeoutMs));+ if (onTimeout) return onTimeout();+ std::fprintf(stderr, "SculptForge: still running %d ms after quitting; ending it\n", timeoutMs);+ std::fflush(stderr);+#if defined(_WIN32)+ TerminateProcess(GetCurrentProcess(), UINT(code));+#endif+ _exit(code);+ }).detach();+}++} // namespace sfdiff --git a/src/core/ExitWatchdog.h b/src/core/ExitWatchdog.hnew file mode 100644index 00000000..99e46bc8--- /dev/null+++ b/src/core/ExitWatchdog.h@@ -0,0 +1,18 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Quitting always ends the process. Armed once the window's loop has ended (the user's work is saved by then): if+// the process is still alive after the timeout (a graphics driver, a thread or a library stuck in the teardown or in+// the exit itself), it ends at once with the exit code, running nothing else (Windows: TerminateProcess, so no DLL+// detach can hang it; elsewhere _exit). A process left behind kept "Playing SculptForge" on Discord (@ebarranco).+#pragma once++#include <functional>++namespace sf {++// Starts a detached thread that waits timeoutMs, then calls onTimeout (tests) or ends the process with code.+// Nothing else changes: a normal exit before then just ends the thread with the process.+void armExitWatchdog(int timeoutMs, int code, std::function<void()> onTimeout = {});++} // namespace sfdiff --git a/src/core/SelfUpdate.cpp b/src/core/SelfUpdate.cppindex a0a31d5c..0504de02 100644--- a/src/core/SelfUpdate.cpp+++ b/src/core/SelfUpdate.cpp@@ -21,6 +21,10 @@#elif defined(__APPLE__)#include <mach-o/dyld.h>#endif+#if defined(__linux__)+#include <sys/stat.h>+#include <unistd.h>+#endifnamespace sf::update {@@ -504,6 +508,30 @@ StartCheck checkPendingAtStart(const std::string& notePath, const std::string& rreturn StartCheck::Counting;}+bool isOldAppImage(const std::string& procDir, const std::string& appImage) {+#if defined(__linux__)+ if (appImage.empty()) return false;+ struct stat st{};+ if (::stat(procDir.c_str(), &st) != 0 || st.st_uid != ::geteuid()) return false;+ std::error_code ec;+ const fs::path exe = fs::read_symlink(fs::path(procDir) / "exe", ec);+ if (ec || exe.filename() != "sculptforge") return false;+ std::ifstream f(fs::path(procDir) / "environ", std::ios::binary);+ std::string env((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());+ const std::string want = "APPIMAGE=" + appImage;+ for (size_t at = 0; at < env.size();) {+ const size_t end = std::min(env.find('\0', at), env.size());+ if (env.compare(at, end - at, want) == 0) return true;+ at = end + 1;+ }+ return false;+#else+ (void)procDir;+ (void)appImage;+ return false;+#endif+}+void confirmStarted(const std::string& notePath) {Pending p;std::error_code ec;diff --git a/src/core/SelfUpdate.h b/src/core/SelfUpdate.hindex ed99b02f..cbf97207 100644--- a/src/core/SelfUpdate.h+++ b/src/core/SelfUpdate.h@@ -159,6 +159,11 @@ StartCheck checkPendingAtStart(const std::string& notePath, const std::string& r// The new version is up: the backup and the note go.void confirmStarted(const std::string& notePath);+// Linux AppImage: the process at procDir (/proc/<pid>) is an earlier SculptForge run from the same AppImage file:+// ours (same user), its program is named sculptforge, and its APPIMAGE is appImage. Anything else (the file manager,+// a shell, another user's process, another copy of SculptForge): false. Always false off Linux.+bool isOldAppImage(const std::string& procDir, const std::string& appImage);+// Windows: the PowerShell helper that waits for this process (`pid`) to end, checks the staged package's hash again,// installs it (the installer silently, or the zip unpacked beside the folder and swapped in, the old folder kept// as .old), starts the new version when `relaunch`, and rolls a portable folder back if the new one exits at once.diff --git a/tests/test_discord_presence.cpp b/tests/test_discord_presence.cppindex 10bd7935..285cb1be 100644--- a/tests/test_discord_presence.cpp+++ b/tests/test_discord_presence.cpp@@ -9,10 +9,15 @@#include "TestHarness.h"#include "core/DiscordPresence.h"+#include "core/ExitWatchdog.h"+#include "core/Sha256.h"#include "core/Json.h"+#include <atomic>#include <chrono>#include <cstring>+#include <fstream>+#include <sstream>#include <random>#include <thread>#include <vector>@@ -83,7 +88,7 @@ TEST(discord_activity_sends_the_name_only) {CHECK(!act.has("details")); // Discord shows the application's name: SculptForgeCHECK(!act.has("state"));// The app icon by URL (Discord's RPC docs: an external https image in large_image, through its media proxy).- CHECK(act["assets"]["large_image"].asString() == "https://sculptforge.app/press/sculptforge-icon-1024.png");+ CHECK(act["assets"]["large_image"].asString() == "https://sculptforge.app/press/sculptforge-app-icon-cube-outline-1024.png");CHECK(act["assets"]["large_text"].asString() == "SculptForge");CHECK(act["timestamps"]["start"].asNumber() == 1793750400.0); // seconds, as in the docs' SET_ACTIVITY exampleCHECK(act["type"].asNumber() == 0.0); // Playing (SET_ACTIVITY takes 0, 2, 3 or 5)@@ -128,6 +133,28 @@ TEST(discord_clear_has_no_activity) {CHECK(h.members().size() == 2);}+// Discord's media proxy caches the image by its URL: the file it names never changes (a new icon, a new name). The+// press icon changed, yet profiles kept the SF mark (@ebarranco).+TEST(discord_icon_url_is_frozen) {+ const std::string url = kLargeImageUrl, site = "https://sculptforge.app/";+ CHECK(url.rfind(site, 0) == 0);+ std::ifstream f(std::string(SF_TEST_DATA_DIR) + "/../../website/" + url.substr(site.size()), std::ios::binary);+ CHECK(f.good());+ std::ostringstream bytes;+ bytes << f.rdbuf();+ // Changed on purpose? Add the new image under a new file name, point kLargeImageUrl at it and pin it here.+ CHECK(sha256Hex(bytes.str()) == "95ce025be2983fb0a6d824fda577e3a0b705dd618102c227420093312261adef");+}++TEST(exit_watchdog_fires_after_its_timeout) {+ std::atomic<bool> fired{false};+ const auto start = std::chrono::steady_clock::now();+ armExitWatchdog(50, 0, [&] { fired = true; });+ for (int i = 0; i < 500 && !fired; ++i) std::this_thread::sleep_for(std::chrono::milliseconds(10));+ CHECK(fired.load());+ CHECK(std::chrono::steady_clock::now() - start >= std::chrono::milliseconds(50));+}+TEST(discord_frame_reader_bounds) {const std::string f = encodeFrame(OpFrame, "{\"evt\":\"READY\"}");CHECK(f.size() == kHeaderSize + 15);@@ -576,4 +603,47 @@ TEST(discord_killed_process_closes_the_connection) {}close(listener);}+// Quitting with a stuck teardown (a driver or a thread that never ends): the watchdog ends the process with its exit+// code, and the Discord connection closes with it, so the status goes (@ebarranco: "Playing SculptForge" stayed).+TEST(exit_watchdog_ends_a_stuck_process) {+ TempSocketDir t;+ const int listener = listenAt(t.dir + "/discord-ipc-0");+ CHECK(listener >= 0);+ if (listener < 0) return;+ EnvVar xdg("XDG_RUNTIME_DIR", t.dir);+ const pid_t pid = fork();+ if (pid == 0) {+ Client* client = new Client("1234567890"); // never destroyed: the teardown is stuck+ Activity a;+ a.show = true;+ client->set(a);+ for (int i = 0; i < 300 && client->activitiesSent() < 1; ++i) std::this_thread::sleep_for(std::chrono::milliseconds(10));+ armExitWatchdog(200, 7);+ std::thread([] { for (;;) std::this_thread::sleep_for(std::chrono::seconds(1)); }).join(); // never returns+ _exit(1);+ }+ std::string activity;+ const int c = acceptSession(listener, activity);+ CHECK(c >= 0);+ int status = 0;+ bool exited = false;+ for (int i = 0; i < 500 && !exited; ++i) { // 5 s at most+ exited = waitpid(pid, &status, WNOHANG) == pid;+ if (!exited) std::this_thread::sleep_for(std::chrono::milliseconds(10));+ }+ if (!exited) {+ kill(pid, SIGKILL);+ waitpid(pid, &status, 0);+ }+ CHECK(exited);+ CHECK(WIFEXITED(status) && WEXITSTATUS(status) == 7);+ if (c >= 0) {+ timeval tv{1, 0};+ setsockopt(c, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);+ char b;+ CHECK(recv(c, &b, 1, 0) == 0); // EOF: closed+ close(c);+ }+ close(listener);+}#endifdiff --git a/tests/test_self_update.cpp b/tests/test_self_update.cppindex 311915f5..f7a5752d 100644--- a/tests/test_self_update.cpp+++ b/tests/test_self_update.cpp@@ -18,6 +18,11 @@#include <fstream>#include <iterator>#include <map>+#include <string>+#include <vector>+#if defined(__linux__)+#include <unistd.h>+#endifusing namespace sf;using namespace sf::update;@@ -361,6 +366,53 @@ TEST(self_update_downloads_and_installs) {CHECK(checkPendingAtStart(s.note, "99.0.0", p, error) == StartCheck::Nothing);}+// The update replaces the AppImage in place: the file keeps the name it had (a copy downloaded as 0.11.1 and updated+// since stays SculptForge-0.11.1-x86_64.AppImage; Help > About shows the version), nothing else appears beside it,+// and versions are whole strings (0.11.10 is never 0.11.1). @ebarranco's 0.11.1 file ran 0.11.10.+TEST(self_update_appimage_names_and_versions) {+ const std::string x86 = "SculptForge-linux-x86_64.AppImage";+ CHECK(versionedAsset(x86, "0.11.10") == "SculptForge-0.11.10-x86_64.AppImage");+ CHECK(versionedAsset(x86, "0.11.11") == "SculptForge-0.11.11-x86_64.AppImage");+ CHECK(versionedAsset(x86, "0.10.0") == "SculptForge-0.10.0-x86_64.AppImage");+ CHECK(versionedAsset(x86, "0.11.11-beta.1") == "SculptForge-0.11.11-x86_64.AppImage");+ struct Step {+ const char *file, *from, *to;+ };+ for (const Step& st : {Step{"SculptForge-0.11.10-x86_64.AppImage", "0.11.10", "0.11.11"},+ Step{"SculptForge-0.9.12-x86_64.AppImage", "0.9.12", "0.10.0"},+ Step{"SculptForge-0.11.1-x86_64.AppImage", "0.11.1", "0.11.10"}}) {+ Sandbox s("sf_self_update_names");+ const fs::path target = s.dir / "Apps" / st.file;+ fs::remove(s.install.target);+ writeAll(target, std::string("old ") + st.from);+ s.install.target = target.string();+ const std::string staged = stagingPath(s.install, st.to), content = std::string("new ") + st.to;+ CHECK(fs::path(staged).filename() == std::string(".download-") + st.to + "-" + x86);+ writeAll(staged, content);+ Download d;+ d.staged = staged;+ d.sha256 = sha256Hex(content);+ std::string error;+ CHECK(installAppImage(s.install, d, st.to, st.from, s.note, error));+ CHECK(readAll(target) == content && readAll(s.install.target + ".old") == std::string("old ") + st.from);+ std::vector<std::string> names;+ for (const auto& e : fs::directory_iterator(s.dir / "Apps")) names.push_back(e.path().filename().string());+ std::sort(names.begin(), names.end());+ CHECK((names == std::vector<std::string>{st.file, std::string(st.file) + ".old"}));+ Pending p;+ CHECK(readPending(s.note, p) && p.version == st.to && p.from == st.from && p.target == s.install.target);+ CHECK(checkPendingAtStart(s.note, st.to, p, error) == StartCheck::Counting && p.starts == 1);+ confirmStarted(s.note);+ CHECK(!fs::exists(s.install.target + ".old") && readAll(target) == content);+ }+ // A note for 0.11.10 doesn't count a start of 0.11.1 (or the other way round): only the exact version.+ Sandbox s("sf_self_update_names_exact");+ CHECK(writePending(s.note, {"0.11.10", "0.11.1", s.install.target, s.install.target + ".old", 0}));+ Pending p;+ std::string error;+ CHECK(checkPendingAtStart(s.note, "0.11.1", p, error) == StartCheck::Abandoned);+}+TEST(self_update_refuses_bad_releases) {struct Case {const char* what;@@ -639,3 +691,34 @@ TEST(self_update_keychain_windows) {CHECK(keychain::erase(account)); // (nothing there: still fine)}#endif++#if defined(__linux__)+// After Restart to update, the new version ends the old one only when it's that old SculptForge from the same AppImage+// file (0.11.10 and earlier stayed hidden and kept running: @ebarranco). A fake /proc/<pid> entry.+TEST(self_update_old_appimage_check) {+ const fs::path dir = fs::temp_directory_path() / ("sf-oldappimage-" + std::to_string(::getpid()));+ fs::remove_all(dir);+ fs::create_directories(dir / "mount" / "usr" / "bin");+ std::ofstream(dir / "mount" / "usr" / "bin" / "sculptforge") << "x";+ std::ofstream(dir / "mount" / "usr" / "bin" / "dolphin") << "x";+ const std::string appImage = "/home/someone/SculptForge/SculptForge-0.11.1-x86_64.AppImage";+ const auto proc = [&](const std::string& name, const std::string& program, const std::string& environ) {+ const fs::path p = dir / name;+ fs::create_directories(p);+ fs::create_symlink(dir / "mount" / "usr" / "bin" / program, p / "exe");+ std::ofstream(p / "environ", std::ios::binary) << environ;+ return p.string();+ };+ const std::string env = std::string("HOME=/home/someone") + '\0' + "APPIMAGE=" + appImage + '\0' + "OWD=/home/someone" + '\0';+ CHECK(isOldAppImage(proc("old", "sculptforge", env), appImage));+ CHECK(!isOldAppImage(proc("other-file", "sculptforge", env), appImage + ".old")); // another copy+ CHECK(!isOldAppImage(proc("prefix", "sculptforge", env), "/home/someone/SculptForge/SculptForge")); // whole value only+ CHECK(!isOldAppImage(proc("filemanager", "dolphin", env), appImage)); // the file manager+ CHECK(!isOldAppImage(proc("no-appimage", "sculptforge", std::string("HOME=/x") + '\0'), appImage));+ CHECK(!isOldAppImage(proc("old2", "sculptforge", env), ""));+ CHECK(!isOldAppImage((dir / "missing").string(), appImage));+ CHECK(!isOldAppImage("/proc/1", appImage)); // init: not ours+ CHECK(!isOldAppImage("/proc/self", appImage)); // the tests: not sculptforge+ fs::remove_all(dir);+}+#endif